3

I have two versions of a file where the newer one has some lines added. The files are sorted (think of wordlists) and I want to print out the newly added lines (given file1 and file2).

I know how to write a little python or perl script to achieve this task, but can it be done with basic UNIX shell utilities, too?

  • Add you sample input and desired output – bluefoggy Feb 17 '15 at 14:12
2

have a look at comm(1).

what you are looking for is

comm -13 file1 file2

or

comm -3 file1 file2
4

Let a.txt be:

aaa
bbb
ccc

Let b.txt be:

aaa
bbb
ccc
ddd
eee

Using comm with -3 you can get the desired result:

comm -3 a.txt b.txt
ddd
eee

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.