Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've got two files, and output of diff looks like this:

33428,33429c33428,33429
< lucid-security|main|icedtea-6-jre-cacao|6b20-1.9.2-0ubuntu1~10.04.1
< lucid-security|main|icedtea6-plugin|6b20-1.9.2-0ubuntu1~10.04.1
---
> lucid-security|main|icedtea-6-jre-cacao|6b20-1.9.4-0ubuntu1~10.04.1
> lucid-security|main|icedtea6-plugin|6b20-1.9.4-0ubuntu1~10.04.1
33835,33842c33835,33842
< lucid-security|main|openjdk-6-dbg|6b20-1.9.2-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-demo|6b20-1.9.2-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-doc|6b20-1.9.2-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-jdk|6b20-1.9.2-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-jre|6b20-1.9.2-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-jre-headless|6b20-1.9.2-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-jre-lib|6b20-1.9.2-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-source|6b20-1.9.2-0ubuntu1~10.04.1
---
> lucid-security|main|openjdk-6-dbg|6b20-1.9.4-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-demo|6b20-1.9.4-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-doc|6b20-1.9.4-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-jdk|6b20-1.9.4-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-jre|6b20-1.9.4-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-jre-headless|6b20-1.9.4-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-jre-lib|6b20-1.9.4-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-source|6b20-1.9.4-0ubuntu1~10.04.1
34182c34182
< lucid-security|universe|openjdk-6-jre-zero|6b20-1.9.2-0ubuntu1~10.04.1
---
> lucid-security|universe|openjdk-6-jre-zero|6b20-1.9.4-0ubuntu1~10.04.1

I would like to "ungroup" the output, so the old line is followed by the new line. Could be looking like this:

< lucid-security|main|icedtea-6-jre-cacao|6b20-1.9.2-0ubuntu1~10.04.1
> lucid-security|main|icedtea-6-jre-cacao|6b20-1.9.4-0ubuntu1~10.04.1
< lucid-security|main|icedtea6-plugin|6b20-1.9.2-0ubuntu1~10.04.1
> lucid-security|main|icedtea6-plugin|6b20-1.9.4-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-dbg|6b20-1.9.2-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-dbg|6b20-1.9.4-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-demo|6b20-1.9.2-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-demo|6b20-1.9.4-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-doc|6b20-1.9.2-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-doc|6b20-1.9.4-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-jdk|6b20-1.9.2-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-jdk|6b20-1.9.4-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-jre|6b20-1.9.2-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-jre|6b20-1.9.4-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-jre-headless|6b20-1.9.2-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-jre-headless|6b20-1.9.4-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-jre-lib|6b20-1.9.2-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-jre-lib|6b20-1.9.4-0ubuntu1~10.04.1
< lucid-security|main|openjdk-6-source|6b20-1.9.2-0ubuntu1~10.04.1
> lucid-security|main|openjdk-6-source|6b20-1.9.4-0ubuntu1~10.04.1
< lucid-security|universe|openjdk-6-jre-zero|6b20-1.9.2-0ubuntu1~10.04.1
> lucid-security|universe|openjdk-6-jre-zero|6b20-1.9.4-0ubuntu1~10.04.1

I don't need the information about position of changed lines, and I don't even care about lines added or deleted in second file. Just this quick compare of changes.

share|improve this question
add comment

1 Answer

A quick regex can nicely sort out which lines are prefixed by a given character.

diff file1 file2 | egrep '^[<>]' > output.txt

That should leave you with just positive and negative changes, no line numbers, no separators.

share|improve this answer
    
That will, in fact, not diff line by line, so you will still have to catch some blocks by eye. stackoverflow.com/questions/2138749/… indicates this cannot be solved with the standard diff utility. –  Jeremy Sturdivant Jan 27 '11 at 11:37
    
You can remove the numbers and separations this way: diff --changed-group-format="%>%<" --unchanged-group-format="" file_1 file_2. –  mkudlacek Jan 27 '11 at 12:46
    
But thank you for pointing me way how to solve my problem. By parameters above I removed also the leading ">" and "<" and then sorted the result with sort. Not general solution, but works in this case. –  mkudlacek Jan 27 '11 at 12:48
add comment

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.