0

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
  • 1
    Look at the "Set Complement" section of the accepted answer to the question this is marked a duplicate of. – Kusalananda Mar 14 '23 at 09:40
  • Try the man page for the `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:41
  • Anyway: `diff <(sort f1) <(sort f2) |grep "<"|cut -d" " -f 2` – K-attila- Mar 14 '23 at 10:03
  • 1
    @K-att- You would not need `grep` nor `cut` if you use `comm` in place of `diff`. The `diff` utility is really only useful to visually inspect differences between files or for generating patches. Note too that in _the general case_, your `grep` would match the `<` character anywhere on the line, and the `cut` command would need to be adjusted if the lines contain spaces. – Kusalananda Mar 14 '23 at 10:21
  • Indeed. I thought it's a special file, but you're right. – K-attila- Mar 14 '23 at 14:59

0 Answers0