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?

1
  • Add you sample input and desired output
    – bluefoggy
    Feb 17, 2015 at 14:12

2 Answers 2

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
2

have a look at comm(1).

what you are looking for is

comm -13 file1 file2

or

comm -3 file1 file2

You must log in to answer this question.

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