I have a list from an inventory and another list from management. I'm trying to find the IP's that are similar between both files then output that is similar into another file:

I tried using diff but, the output did not made sense.

diff -buy list1 list2

then I tried to use egrep using IP's from list 1but, I think I used the wrong syntax.

egrep -o `192.168.*|192.1.69` list2

not sure what to use correctly

like: list 1 maybe have:

and I want to try to find this IPs in list2

  • 2
    Could you please post example data?
    – phk
    Feb 7, 2017 at 17:21
  • 1
    Please edit your post instead of trying to fit it into the comments.
    – phk
    Feb 7, 2017 at 17:27
  • Yes, please post short sample of inputs and expected output.
    – dhag
    Feb 7, 2017 at 17:27
  • exactly those IP's from list1, or "similar" IP's meaning the same first two octets?
    – Jeff Schaller
    Feb 7, 2017 at 17:34
  • @JeffSchaller those exact IP's
    – jlozadad
    Feb 7, 2017 at 17:39

1 Answer 1


Solution in bash or a similar shell with process substitution using the <(...) form:

comm -1 -2 <(sort list1) <(sort list2)

Should you have duplicate entries in list2 then add the -u option to the sort call.

Not the answer you're looking for? Browse other questions tagged .