I have awk command to output matched rows data comparing on 2 columns, although I would like to output the opposite, unmatched data.
#file1.csv
box1,apple
box2,banana
#file2.csv
data24,box1,apple,text
date25,box1,banana,text
And by AWK I have,
awk -F',' 'NR==FNR{a[$1,$2]; next} ($2,$3) in a' file1.csv file2.csv
The output looks like:
data24,box1,apple,text
And would like to have:
banana,box2
Simple negation seems does not work in this case, do you have any ideas please? Have tried :
awk -F',' 'NR==FNR{a[$1,$2]=1; next} !($2,$1) in a' file1.csv file2.csv
Which will output:
data24,box1,apple,text
date25,box1,banana,text
$ awk 'BEGIN{FS=OFS=","} NR==FNR{a[$2,$3]; next} !(($1,$2) in a){print $2, $1}' file2.csv file1.csv
banana,box2
Instead of reversing the logic, you can reverse the action:
awk -F',' 'NR==FNR{a[$1,$2]; next} ($2,$3) in a {next}1' file1.csv file2.csv
date25,box1,banana,text
Or:
awk 'BEGIN{FS=OFS=","}
NR==FNR{a[$1,$2]; next} ($2,$3) in a {next} {print $2, $3}' file1.csv file2.csv
box1,banana
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With