Computing.Net > Forums > Unix > Grep Help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Grep Help

Reply to Message Icon

Name: ChrisS
Date: December 9, 2003 at 15:13:47 Pacific
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?




Sponsored Link
Ads by Google

Response Number 1
Name: LANkrypt0
Date: December 9, 2003 at 16:05:20 Pacific
Reply:

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.


0

Response Number 2
Name: shailesh.bhide
Date: December 10, 2003 at 03:17:12 Pacific
Reply:

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


0

Response Number 3
Name: ChrisS
Date: December 10, 2003 at 15:43:17 Pacific
Reply:

Thanks to you both...


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Who Command Perl: Split Function &...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Grep Help

grep Help www.computing.net/answers/unix/grep-help/6804.html

grep help www.computing.net/answers/unix/grep-help/4368.html

Grep help www.computing.net/answers/unix/grep-help/6151.html