user1004985 user1004985 - 14 days ago 5
Linux Question

How to get the difference (only additions) between two files in linux

I have two files A1 and A2 (unsorted). A1 is previous version of A2 and some lines have been added to A2. How can I get the new lines that are added to A2?

Note: I just want the new lines added and dont want the lines which were in A1 but deleted in A2. When i do

diff A1 A2
, I get the additions as well as deletions but I want only additions.

Please suggest a way to do this.

Answer

diff and then grep for the edit type you want.

diff -u A1 A2 | grep -E "^\+"
Comments