I have two files that have some similar and some unique columns. I'd like to compare the first 3 columns that are similar and print if they match, along with each of their unique columns.
File1:
A cat pizza 34 24 56
A dog tomato 304 959 030
B bird grape 4.4 939 33
C snake broccoli 89 28 273
File2:
A cat pizza 55 85 328
B dog tomato 404 56 32
C snake sandwich 384 34 75
Which should make
File3:
A cat pizza 34 24 56 55 85 328
I've been trying
awk 'NR==FNR {c[$1$2$3]++;next}
c[$1$2$3] > 0 {print $0}'
but I'm not getting any matches.
file1
andfile2
as above, and run your unchanged command with the two files as parameters, I do getA B C G H I
. However, what output do you want to generate when there is more than one match, e.g. more than one line starts withA B C
?c[$1,$2,$3]
(with commas) -- that puts a separator between the strings so you won't get false positives, such asA A AA
in file 1 andAA A A
in file 2I'd like to compare the first 3 columns that are similar
do you mean you always want to compare only the first 3 columns or you literally want to compare the first 3 columns that are similar out of N that might be similar, and, by similar do you actually mean identical or something else, and does order matter such that A B C in file1 matches A C B in file2, etc.? Please edit your question to clarify your requirements.