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
Ignore some lines with specific words from file comparison jakSun8 Shell Programming and Scripting 2 03-12-2008 08:11 PM
Search File for Specific Words mevasquez UNIX for Dummies Questions & Answers 2 12-04-2007 12:31 PM
Tar Exclude Dir with a Specific Words rhartleyoh UNIX for Dummies Questions & Answers 1 07-26-2007 07:53 AM
How to search files containing a specific word in the content amjath78 UNIX for Dummies Questions & Answers 1 01-03-2007 11:42 AM
Search all files for specific string sureshy UNIX for Dummies Questions & Answers 4 03-06-2002 08:28 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-21-2007
Registered User
 

Join Date: Jan 2007
Posts: 7
Stumble this Post!
Search files that all contain 4 specific words

Hello,

I want an one line command that brings me back all the files in a folder that contain 4 specific words anywhere inside them.

I want to use find,xargs and grep. for example i know for one word the command would be:

find . | xargs grep 'Word1'

But i don't know for 4 specific words what i should do.

Thanx
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-21-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,540
Stumble this Post!
you can use egrep "word1|word2|word3|word4"
Reply With Quote
  #3 (permalink)  
Old 01-21-2007
Registered User
 

Join Date: Jan 2007
Posts: 7
Stumble this Post!
thank you,
but i don't think that this is what i want.this will give me and the files that only contain word1 and not word2 and word3 and word4.

I want the files returned to contain all 4 words
Reply With Quote
  #4 (permalink)  
Old 01-21-2007
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,242
Stumble this Post!
Try...
Code:
find . -type f | xargs perl -0 -n -e 'print $ARGV."\n" if /word1/&&/word2/&&/word3/&&/word4/'
Reply With Quote
  #5 (permalink)  
Old 01-22-2007
Registered User
 

Join Date: Jan 2007
Posts: 7
Stumble this Post!
Well thank you very much,

but i don't want to use the command perl. I want to use the commands find,xargs and grep. Is it possible??
Reply With Quote
  #6 (permalink)  
Old 01-22-2007
Registered User
 

Join Date: Dec 2006
Location: CA,United States
Posts: 172
Stumble this Post!
try egrep

find . | xargs egrep "word1|word2|word3"
Reply With Quote
  #7 (permalink)  
Old 01-22-2007
Registered User
 

Join Date: Jan 2007
Posts: 7
Stumble this Post!
thank you,
but i said to the previous post this is not what i want.this will give me and the files that only contain word1 and not word2 and word3 and word4.

I want the files returned to contain all 4 words.Also i want to use the commands find,xargs and grep.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:43 AM.


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

Content Relevant URLs by vBSEO 3.2.0