Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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'
share|improve this question

3 Answers 3

up vote 7 down vote accepted

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
share|improve this answer
    
Awesome. Shame the info is buried in the Texinfo and no hint is provided in the man page I was reading.. –  Robottinosino Nov 25 '12 at 15:05

You have to add one more option :

grep -vf file1 file2
share|improve this answer
awk 'FNR==NR{old[$0];next};!($0 in old)' old.txt new.txt
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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