you need grep -q (Chant man grep then check the -q option, then experiment a little bit until you understand how it works.) Hint: A zero status is the way Unix utilities signal 'it worked'; so you can use it in a logic test.
griswolf
Veteran Poster
1,165 posts since Apr 2010
Reputation Points: 344
Solved Threads: 256
cat filename | grep word | echo "$?"
if the result of above oneliner is 0 it means the word is there in the file . if it's non zero
it means word is not there.(echo "$?" tells us whether the previous command was successful
or not)
let say your file is abc.txt and you want to search the word "john" in it.
cat abc.txt | grep john | echo "$?"
# why this:
cat filename | grep word
# instead of:
grep word filename
thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75