tags:

views:

36

answers:

2

Hey!

I have two lists of IP addresses. I need to merge them into three files, the intersection, those from list1 only and those from list2 only.

can I do this with awk/diff or any other simple unix command? How?

The files look like this:

111.222.333.444
111.222.333.445
111.222.333.448

Thank you!

+3  A: 

First sort them, using sort, and then you can use comm.

Intersection: comm -12 <file1> <file2>

List 1 Only: comm -23 <file1> <file2>

List 2 Only comm -13 <file1> <file2>

Brandon Horsley
Or just plan "comm <file1> <file2>", giving three columns, with "file 1 only", "file 2 only" and "common" (as long as the input files are sorted).
Vatine
+4  A: 

If the files are sorted then

join list1 list2

will output the intersection.

join -v 1 list1 list2

will output the ones that are in list1 only.

join -v 2 list1 list2

will output the ones that are in list2 only.

Dennis Williamson