The UNIX and Linux Forums  

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


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep Three Words murbina UNIX for Dummies Questions & Answers 12 08-14-2008 12:38 AM
grep on multiple words to match text template rider29 Shell Programming and Scripting 6 05-23-2008 08:21 AM
How to extract two words at the same time. Aejaz UNIX for Advanced & Expert Users 6 04-30-2008 06:09 AM
grep with find to search for matchiing words akhil313 UNIX for Dummies Questions & Answers 1 12-12-2006 06:18 AM
find words with grep.... chrisxgr Shell Programming and Scripting 8 04-06-2006 10:25 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-28-2006
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
Forum Sponsor
  #2 (permalink)  
Old 02-28-2006
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,243
Perhaps use an extended regular expression...
Code:
egrep '(file.*testfile|testfile.*file)' file*
Reply With Quote
  #3 (permalink)  
Old 03-01-2006
Registered User
 

Join Date: Mar 2006
Posts: 2
ooppp

oops sorry.... nm (edit)

Last edited by CL_KB; 03-01-2006 at 08:55 PM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:23 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0