I have file1 and file2.
file1:
a james
b mike
d john
file2:
a 10 20 30 40
b 11 12 13 14
c 20 30 40 50
d 10 20 30 50
I want the output file to only find the difference in column 1, and print that line for file2. In this case: C. so file3 look like:
c 20 30 40 50
I think the proper command is comm
, but I don't think I'm using the right switches because every combination I can think of isn't giving me the right results.
comm
, we can assume the first column is sorted? Great! As a first step: in a shell likebash
that has process substitution we can do:comm <(cut -d ' ' -f 1 file1 ) <(cut -d ' ' -f 1 file2)
– phk Jul 3 '16 at 20:58file1
andfile2
, you should see what is missing infile2
on the left side, like I said, it would only be a first step. Oh and BTW, if you add-13
to thecomm
call from me you will only see the differing entries in the first column, so you can then use this to select fromfile2
:grep "^$(comm -13 <(cut -d ' ' -f 1 file1 ) <(cut -d ' ' -f 1 file2))" file2
– phk Jul 3 '16 at 21:30