I want to search for "STRING1" using
grep but to skip if the line contains "STRING2". How can I do it?
This will do:
grep -v "STRING2" file | grep "STRING1"
You might want to consider using
perl instead of
awk '/STRING1/ && !/STRING2/' file
perl -ne 'print if /STRING1/ && !/STRING2/' file
See also grep with logic operators .