取消分组 diff 的输出

取消分组 diff 的输出

我有两个文件,其输出diff如下所示:

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

我想“取消组合”输出,这样旧行后面就是新行。可能看起来像这样:

< 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

我不需要有关更改行的位置的信息,甚至不关心第二个文件中添加或删除的行。只需快速比较更改即可。

答案1

快速正则表达式可以很好地找出以给定字符为前缀的行。

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

这样就只会留下正数和负数的变化,没有行号,也没有分隔符。

相关内容