0

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.

1

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.

  • 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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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