Assuming both files have the same number of lines:
awk '{getline f2 < "file2"; print f2 == $0 ? "TRUE" : "FALSE"}' file1
That's doing a numerical comparison if the strings to compare are numbers and lexical otherwise. For instance, 100
and 1.0e2
would be considered identical. Change to f2"" == $0
to force a lexical comparison in any case.
Depending on the awk
implementation, lexical comparison will be done as if by using memcmp()
(byte-to-byte comparison) or as if by using strcoll()
(whether the two strings sort the same in the locale's collation order). That can make a difference in some locales where the order is not properly defined for some characters, not on all decimal digit input like in your sample.
diff
. – Panki Apr 17 '19 at 09:36comm
. It makes it easy to list lines that both files have in common or are unique to one or the other. – Giacomo Alzetta Apr 17 '19 at 12:12comm
is that it requires sorted input. Apart from the fact that the example in the question does have sorted input, the question never asserts that this is the actual data that is being used and never says anything about the ordering of the data. – Kusalananda Apr 17 '19 at 13:52nl
trick is useful withcomm
for imposing sorted-ness on the files. – glenn jackman Apr 17 '19 at 18:06