Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences/merging two files

Tags:

shell

awk

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!

like image 205
Zenet Avatar asked Jul 29 '10 16:07

Zenet


People also ask

How do you compare and merge two files?

You can also merge two versions of the same document into one new document. In both cases, Word shows the differences with revision marks. Open one of the two versions of the document that you want to compare. On the Tools menu, point to Track Changes, and then click Compare Documents.

What Compare merge files?

File Compare/Merge is a graphical file and folder comparison and merge tool delivered with StarTeam. It enables you to compare the contents of two files or folders, and manually or automatically merge the contents.

How do I compare two folders in merge?

With the two folders selected, right-click and choose Compare (or click Merge → Compare in the menu).


1 Answers

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.

like image 152
Dennis Williamson Avatar answered Sep 25 '22 15:09

Dennis Williamson