The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 02-28-2006
ElCaito ElCaito is offline
Registered User
 

Join Date: Feb 2006
Location: Melbourne
Posts: 11
How to grep for two or more words in a line at the same time?

I want to search a heap of files but using an either OR or AND condition for two or more strings. How can I do this?

i.e. file1 has the following

file testfile primary

and file2 has this ...

file testfile2 secondary

If I use this ...

find . -type f -exec grep "testfile" {} /dev/null \;

I get BOTH files.

However, I want to use something that will give me the 1st file if I say something like ...

find . -type f -exec grep "file&&testfile" {} /dev/null \;

This actually did not work under C shell or Korn shell.

I also tried egrep "file&&testfile" and it too did not work.

In VMS (here we go! hehehe)... it was so easy ...

search *.src file, testfile /match=and

Thanks in advance
Reply With Quote
Remove advertisements
!!
Forum Sponsor