Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.
fi
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.