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

closed as unclear what you're asking by Toby Speight, Jeff Schaller, GAD3R, roaima, mdpc Feb 8 '17 at 1:17

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

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

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 or ask your own question.