Take the 2-minute tour ×

I want to search if "ack_enabled not defined" is not there in a particular file all_defs.txt and return something, by which i can understand that the string is not there.

Can anyone tell me how to do it?

Also, the second part is that, i have a a list of strings stored in a file. Each line has a multiworded string that has to be checked individually if present in another file.

share|improve this question

2 Answers 2

Just check the exit code of grep. -q makes it silent, ! negates the exit code:

if ! grep -q 'ack_enabled not defined' all_defs.txt ; then
    echo Not found.
share|improve this answer

Here is a one-liner which is even more verbose:

grep -q 'ack_enabled not defined' all_defs.txt && echo 'string found' || echo 'string not found'
share|improve this answer

Your Answer


