Vonton
Vonton

Reputation: 3372

compare two files (understanding)

I am trying to understand of awk comparsion of two fields from different files. (all files are tab delimited)

1st file:

1   11796321
1   169549811
1   173917078
2   48962782
4   121696962
4   121697011

2nd file:

a 0 1 2 0 b 1 11796321 a
b 0 1 0 2 c 1 11800000 bd
c a d 0 0 2 4 121696962 0

OUTPUT:

 b 0 1 0 2 c 1 11800000 bd

So I would like to compare $1 and 2nd column from 1st file with 7th and 8th column in 2nd file and print unmatched.

I tried:

awk -v OFS="\t" -F '\t' 'FNR==NR{a[$1,$2]; next} ($7,$8) in a {next} {print $0}' file1 file2 

Could you help understand where is mistake and how could I compare this files? Thank you.

Upvotes: 0

Views: 58

Answers (2)

karakfa
karakfa

Reputation: 67507

change to

$ awk -v OFS="\t" -F'\t' 'FNR==NR{a[$1,$2]; next} !(($7,$8) in a)' file1 file2

Upvotes: 1

Kent
Kent

Reputation: 195169

If the delimiter in both files are the same (<tab>), you can try this:

awk -F '\t' 'FNR==NR{k=$1 FS $2;a[k];next} !($7 FS $8  in a)' file1 file2 

Upvotes: 1

Related Questions