I would like to do the inverse of this (exactly same example): Extract rows from file_1 based on matching the first two columns from a file_2

That is, extract all rows from file_1 except those with the first two columns matching the first two columns from file_2.


awk 'NR==FNR {get[$1" "$2]++; next} !get[$1" "$2]' f2.txt f1.txt
  • 1
    You can use the logical negation of the previous condition: !($1" "$2 in a) – steeldriver Jan 22 '19 at 1:46

This should work:

$ awk 'NR==FNR {get[$1" "$2]++; next} !get[$1" "$2]' f1.txt f2.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.