Diff, show modified line from right file only

I have file a and b and I would like to output lines of b that changed since it was cloned from a. Just the modified lines, no surrounding context, no diff offset marks.

How can I do that using shell scripting? (No Python/Perl/PHP/…)

Sed and awk are acceptable solutions.

For now, what I am doing is diff -y with –suppress-common-lines and sed using regex backreferences to just fetch the right part after the whitespace. There must be a better way?

Using perl (which is forbidden), I´d do something like this:

diff -y --suppress-common-lines -W $COLUMNS Eclipse_Preferences_Export_*.epf | perl -pe 's/.*t|t(.*)$/1/g'

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

With GNU diffutils package’s diff this will output only lines from file b which either were modified or newly inserted:

diff --unchanged-line-format= --old-line-format= --new-line-format='%L' a b

Method 2

You have to add one more option :

grep -vf file1 file2

Method 3

awk 'FNR==NR{old[$0];next};!($0 in old)' old.txt new.txt


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments