I have two sets of files containing ip addresses
file 1
1.1.1.1
2.2.2.2
3.3.3.3
file 2
1.1.1.1
2.2.2.2
4.4.4.4
5.5.5.5
I need to compare two file and print the entry present in file 1 but not in file 2, that is desire output should be
3.3.3.3
comm
command. Note it only works for sorted files (which yours appear to be). If this is not strictly correct, you would need to pre-sort both files. – Paul_Pedant Mar 14 '23 at 09:41diff <(sort f1) <(sort f2) |grep "<"|cut -d" " -f 2
– K-attila- Mar 14 '23 at 10:03grep
norcut
if you usecomm
in place ofdiff
. Thediff
utility is really only useful to visually inspect differences between files or for generating patches. Note too that in the general case, yourgrep
would match the<
character anywhere on the line, and thecut
command would need to be adjusted if the lines contain spaces. – Kusalananda Mar 14 '23 at 10:21