The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
search two words in sed ajitkumar2 Shell Programming and Scripting 12 08-01-2008 12:00 AM
grep on multiple words to match text template rider29 Shell Programming and Scripting 6 05-23-2008 08:21 AM
problem with grep on search string in a txt file over multiple files m00 UNIX for Dummies Questions & Answers 2 05-18-2008 11:21 AM
grep with find to search for matchiing words akhil313 UNIX for Dummies Questions & Answers 1 12-12-2006 07:18 AM
multiple search with grep amon Shell Programming and Scripting 5 04-04-2006 03:53 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 08-22-2008
Registered User
 

Join Date: Aug 2008
Location: India
Posts: 108
for FILE in `ls -1 *.log`
do
w1=`cat $FILE|grep -c "word1"`
w2=`cat $FILE|grep -c "word2"`
if [ ${w1} -gt 0 -a ${w2} -gt 0 ]
then
echo "$FILE"
fi
done
Reply With Quote
Forum Sponsor
  #9  
Old 08-22-2008
vidyadhar85's Avatar
The Tutor
 

Join Date: Jun 2008
Location: INDIA
Posts: 549
try...
egrep -l "word[1-2]" *
or
egrep -l "word1|word2" *
Reply With Quote
  #10  
Old 08-22-2008
Registered User
 

Join Date: Aug 2008
Location: India
Posts: 108
for FILE in `ls -1 *.log`
do
w1=`cat $FILE|grep -c "word1"`
w2=`cat $FILE|grep -c "word2"`
if [ ${w1} -gt 0 -a ${w2} -gt 0 ]
then
echo "$FILE"
fi
done
Reply With Quote
  #11  
Old 08-22-2008
Registered User
 

Join Date: Aug 2008
Posts: 18
Hi Palsevlohit

Thank U very much yaar ,its working fine.............

i have one more dout, is is possible to do using grep or find..........
Reply With Quote
  #12  
Old 08-22-2008
vidyadhar85's Avatar
The Tutor
 

Join Date: Jun 2008
Location: INDIA
Posts: 549
i don't think you need a script for it...
Reply With Quote
  #13  
Old 08-22-2008
Registered User
 

Join Date: Aug 2008
Posts: 18
Hi vidya

egrep -l "word1|word2" *

i have tried this one but its given all file names....its working like or command

but i want files that should be word1 and word2 , the above script working fine but if possible could you please send unix command....
Reply With Quote
  #14  
Old 08-22-2008
vidyadhar85's Avatar
The Tutor
 

Join Date: Jun 2008
Location: INDIA
Posts: 549
try this....
Quote:
grep -l "word1" *.log|xargs grep -l "word2"
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:43 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 Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0