From: Chris on
Hi
I have a file containing 2 words on 2 seperate lines:

e.g.

car
bike

I want to pipe this file through sed or awk, and only return the
output only **both** words are found. Could someone help me do this?
As they are on different lines grep wont work.

Thanks
From: Fred on
On Aug 11, 10:26 am, Chris <cconnel...(a)lycos.com> wrote:
> Hi
> I have a file containing 2 words on 2 seperate lines:
>
> e.g.
>
> car
> bike
>
> I want to pipe this file through sed or awk, and only return the
> output only **both** words are found. Could someone help me do this?
> As they are on different lines grep wont work.
>
> Thanks


You need to provide more information to get a meaningful answer.
What output do you want?
- the entire file?
- just the lines containing 'car' and 'bike' ?
- is order important ?
- can the lines contain other text, or must the lines contain only the
searched-for text?
--
Fred K
From: pk on
On Wed, 11 Aug 2010 10:26:47 -0700 (PDT) Chris <cconnell_1(a)lycos.com> wrote:

> Hi
> I have a file containing 2 words on 2 seperate lines:
>
> e.g.
>
> car
> bike
>
> I want to pipe this file through sed or awk, and only return the
> output only **both** words are found. Could someone help me do this?

Which output are you talking about?

> As they are on different lines grep wont work.

You can pipe two greps but without knowing what it is that you want to
output it's difficult to tell.

What do you want to output? Matching lines? The whole file? The file name?
From: Chris on
On Aug 11, 7:20 pm, pk <p...(a)pk.invalid> wrote:
> On Wed, 11 Aug 2010 10:26:47 -0700 (PDT) Chris <cconnel...(a)lycos.com> wrote:
>
> > Hi
> > I have a file containing 2 words on 2 seperate lines:
>
> > e.g.
>
> > car
> > bike
>
> > I want to pipe this file through sed or awk, and only return the
> > output only **both** words are found. Could someone help me do this?
>
> Which output are you talking about?
>
> > As they are on different lines grep wont work.
>
> You can pipe two greps but without knowing what it is that you want to
> output it's difficult to tell.
>
> What do you want to output? Matching lines? The whole file? The file name?

I would like to return the matching lines. But only print the lines if
both strings exist in the file.


From: pk on
On Wed, 11 Aug 2010 10:44:52 -0700 (PDT) Chris <cconnell_1(a)lycos.com> wrote:

> On Aug 11, 7:20 pm, pk <p...(a)pk.invalid> wrote:
> > On Wed, 11 Aug 2010 10:26:47 -0700 (PDT) Chris <cconnel...(a)lycos.com>
> > wrote:
> >
> > > Hi
> > > I have a file containing 2 words on 2 seperate lines:
> >
> > > e.g.
> >
> > > car
> > > bike
> >
> > > I want to pipe this file through sed or awk, and only return the
> > > output only **both** words are found. Could someone help me do this?
> >
> > Which output are you talking about?
> >
> > > As they are on different lines grep wont work.
> >
> > You can pipe two greps but without knowing what it is that you want to
> > output it's difficult to tell.
> >
> > What do you want to output? Matching lines? The whole file? The file
> > name?
>
> I would like to return the matching lines. But only print the lines if
> both strings exist in the file.

So you can do, for example

awk '/car/ {c++;ok=1}
/bike/ {b++;ok=1}
ok {lines[++count]=$0;ok=0}
END {if(c && b){for(i=1;i<=count;i++)print lines[i]}}' file.txt