Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

More vebose one-liner

The following one-liner is even more verbose:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .