compare two files, selected columns only

hi! i have two files that looks like this

file 1:
ABS 123 456
BCDG 124 542
FGD 459 762

file 2:
ABS 132 456
FGD 459 762

output would be:

from file1:
ABS 132 456
BCDG 124 542

from file 2:
ABS 132 456

i want to compare these 2 files, but columns 2&3 will be compared. the output would be in two parts. FROM FILE 1, those with difference with file 2 and those lines that cant be found on file 2. And FROM FILE 2, those with difference with file 1 and those lines that cant be found on file 1. Thanks!

--- removed ---

# awk 'NR==FNR{a[$2$3]=$0;next}!a[$2$3]' file2 file1
ABS 123 456
BCDG 124 542
# awk 'NR==FNR{a[$2$3]=$0;next}!a[$2$3]' file1 file2
ABS 132 456

@

your code has a bug at a[$2$3], if $2 and $3 are (12 3456) and (123 456), awk will think they are same: a[123456]

Here is the fix.

$ cat file1
BCDG 124 542
FGD 459 762
ABS 13 2456

$ cat file2
ABS 132 456
FGD 459 762


awk 'NR==FNR{a[$2 FS $3]++;next}!a[$2 FS $3]' file1 file2

ABS 132 456


awk 'NR==FNR{a[$2 FS $3]++;next}!a[$2 FS $3]' file2 file1

BCDG 124 542
ABS 13 2456

That's correct, Thanks :wink: