Use this awk one liner:
awk '$5 ~ /^(A|B|C|D)$/' *.csv
It iterates over all lines of all .csv
files in the current directory and checks if the 5th column ($5
) matches (~
) the pattern ^(A|B|C|D)$
. If the line matches the pattern awk will print the whole line. We have not specified an action but printing the whole line is awk's default action.
The pattern:
^
matches the begin of the string and $
matches the end of the string. Therefore the pattern matches from beginning to the end. (A|B|C|D)
represents a choise of possible values, like a logical OR
operation in other programming languages. I've used the single characters A,B,C,D
as in your question but you are free to use something like (foo|bar|hello|world)
.