I have two text files, each with a single column,
file 1:
124152970
123899868
123476854
54258288
123117283
file 2:
124152970
123899868
54258288
123117283
122108330
I am trying to identify the value in red above which is the first value that doesn't match the second file. I need to print that value and exit.
At first I tried diff,
diff file1 file2 | head -n 2
This gives what I want, but there are multiple lines of output and so it was more steps to get the value into a bash variable, which is what I need.
I then tried awk,
awk ' NR==FNR { a[NR]=$0; next } !($0 in a){ print $1; exit } ' file2 file1
Note that the order of input files is reversed because I want the first line of file1 that does not match file2. This just prints the first line of file1. Even if it did work, I think that this just tells me that the value is, or is not, in the file, not if the lines match.
but that doesn't do anything at all. Am I right that evaluating !($0 in a) looks for $0 anywhere in a? I am checking that the files match, so it matters that the value appears on the same line in both files, not that it appears anywhere.
By slower I mean 0m0.391s as opposed to 0m0.156s with the first method. Not enough difference to bother with but I guess you need some reason to pick a method.
The method suggested by rdrtx1 also worked but again was a bit slower,