Awk team to compare two files
-
I'd like to see the following design:
awk 'NR==FNR{a[$1];next}!($1 in a){print $1}' 1.txt 2.txt
That's what I hope I understand correctly:
{a[$1];}
it's filling the mass. a First words of each line in file 1.txt
!($1 in a){print $1}
print the first words of each line of file 2.txt in 3.txt, if we don't find them in the mass a
But what?
NR==FNR{a[$1];next}
Exactly.NR==FNR
andnext
?I'll be grateful for the explanation.
-
In the violin.
NR==FNR{a[$1];next}!($1 in a){print $1}
Two rules:NR==FNR{a[$1];next}
- this rule is implemented for all lines for which the row number in the file (replaceable)FNR
) coincides with the row number in all files (replaceable)NR
) In fact, this condition means a line from the first file. Modified$1
- that's the first word in the line.a[$1]
creates in the massa
key recording$1
♪next
Means that the current line should be stopped and moved to the next. That is, the second rule will not be applied to the construction of the first file. The first rule creates a lot of words with which lines start in the first file.!($1 in a){print $1}
- this rule shall be implemented provided!($1 in a)
i.e. for those lines where the first word does not appear among the keys of the massa
♪ This rule prints the first word of the corresponding lines.
Total, this violin prints the original words from the second to third consecutive files from which the lines of the first file did not start.