Computing.Net > Forums > Unix > Grep Help

Grep Help

Reply to Message Icon

Original Message
Name: ChrisS
Date: December 9, 2003 at 15:13:47 Pacific
Subject: Grep Help
OS: Unix
CPU/Ram: Solaris
Comment:

I need to search all my log files for 2 specific words and list only the files that contain them. These words will not be on the same line. I can do a grep on one word:
>grep -il chris *
I tried >grep -il "chris".*"help" *.txt
but it stops at the new line char..

I have tried to pipe "|" one grep into another but it doesn't seem to work.
Can anyone help with the syntax to do it in one command?



Report Offensive Message For Removal


Response Number 1
Name: LANkrypt0
Date: December 9, 2003 at 16:05:20 Pacific
Subject: Grep Help
Reply: (edit)

Not at a unix box, but I believe you could, if the files are similary named OR in the same directory:

for files in `ls`;do
if [[ `grep -il chris $files` != "" && `grep -il help $files` != "" ]];then
echo $files
fi
done

you can also use ls *.txt if they are the only text files.

Try that.

Also, I think the page will break the code up, but the line from if to then should all be on the same line.


Report Offensive Follow Up For Removal

Response Number 2
Name: shailesh.bhide
Date: December 10, 2003 at 03:17:12 Pacific
Subject: Grep Help
Reply: (edit)

try using
grep -il -e "chris" -e "help" *.txt


Report Offensive Follow Up For Removal

Response Number 3
Name: ChrisS
Date: December 10, 2003 at 15:43:17 Pacific
Subject: Grep Help
Reply: (edit)

Thanks to you both...


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Grep Help

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software