awk for multiple patterns

Your present condition is not correct as both $1!="C" and $1!="D" can't be false at the same time. Hence, it will always print the whole file.

This will do as you described:

awk '{if ($1!="C" && $1!="D") {print $0}}'  file

Using awk, you can provide rules for specific patterns with the syntax

awk 'pattern {action}' file

see the awk manual page for the definition of a pattern. In your case, you could use a regular expression as a pattern with the syntax

awk'/regular expression/ {action}' file

and a basic regular expression which would suit your needs could be

awk '/^[^CD]/ {print $0}' file

which you can actually shorten into

awk '/^[^CD]/' file

since {print $0} is the default action, as suggested in the comments.


awk '$1 ~ /[CD]/' file

awk '$1 ~ /[LHS]/' file

awk '$1 ~ /[^LHS]/' file

awk '$1 !~ /[LHS]/' file