0
votes

I need to print all the lines in a CSV file when 3rd field does not matches a pattern in a pattern file. I've been doing the opposite, printing matches with the following script:

awk -F, 'FNR == NR { patterns[$0] = 1; next } patterns[$3]' FILE2 FILE1

FILE1

dasdas,0,00567,1,lkjiou,85249
sadsad,1,52874,0,lkjiou,00567
asdasd,0,85249,1,lkjiou,52874
dasdas,1,48555,0,gfdkjh,06793
sadsad,0,98745,1,gfdkjh,45346
asdasd,1,56321,0,gfdkjh,47832

FILE2

00567
98745
45486
54543
48349
96349
56485
19615
56496
39493

OUTPUT

dasdas,0,00567,1,lkjiou,85249
sadsad,0,98745,1,gfdkjh,45346

How can I print lines not matching patterns in pattern file? Thank you very much!

2
Do not use the word "pattern" as it is highly ambiguous. Are you looking to match on a number, a string or a regexp? Are you looking for a full or partial match? - Ed Morton

2 Answers

1
votes

Invert the selection:

#                                             v-- here
awk -F, 'FNR == NR { patterns[$0] = 1; next } !patterns[$3]' FILE2 FILE1
0
votes

You just need invert the match from your previous question

grep -vf <( sed -e 's/^\|$/,/g' file2) file1

PS. see the -v flag