# line containing 'cake' but not 'at' # same as: grep 'cake' table.txt | grep -v 'at' # with PCRE: grep -P '^(?!.*at).*cake' table.txt $ awk '/cake/ && !/at/' table.txt blue cake mug shirt -7
It should be easier to use awk over bash, especiallly for AND conditions.
For example, for "line containing cake
but not at
":
* grep: grep 'cake' table.txt | grep -v 'at'
* grep with PCRE: grep -P '^(?!.*at).*cake' table.txt
* awk: awk '/cake/ && !/at/' table.txt