unix-diff命令以单行/每行格式输出 [英] unix - diff command to output in single-line-per-difference format
问题描述
我的cygwin中diff的版本有许多高级选项,使我可以每行打印出一个差异。
The version of diff in my cygwin has a number of advanced options which allow me to print out one difference per line.
给出两个文件one.txt和两个.txt。
Given two files one.txt and two.txt.
one.txt:
one
two
three
four
five
six
two.txt
one
two2
three
four
five5
six
然后在cygwin中使用以下选项/参数运行diff:
And running diff in cygwin with the following options/parameters:
diff -y --suppress-common-lines one.txt two.txt
给出以下输出:
two |two2
five |five5
这是我追求的格式类型,每行打印一个差异。
在我的dev solaris框上,不支持 -y选项,因此我的输出看起来像这样:
This is the type of format I'm after whereby one difference is printed out per line. On my dev solaris box, the "-y" option is not supported, so I'm stuck with an output which looks like this:
2c2
< two
---
> two2
5c5
< five
---
> five5
有人知道我可以在此solaris盒上每行输出一个差异的方法吗? ?也许使用sed / awk一个内衬来按摩来自这个更原始的diff输出的输出? (请注意,我无法在此solaris盒子上安装最新的diff版本。)。
Does anyone know of a way I can get an output of one difference per line on this solaris box? Maybe using a sed/awk one liner to massage the output from this more primitive diff output? (Please note, I am not able to install a more up-to-date diff version on this solaris box).
谢谢!
推荐答案
使用GNU差异。
http://www.gnu.org/software/diffutils/
您可以构建和安装它进入您的本地目录,不是吗?如果您有主目录,编译器和make,则可以构建自己的GNU差异。
You can build and install it into your local directory, no? If you have a home directory and a compiler and a make, you can build your own GNU diff.
我没有Solaris,但我无法想象会比这更多:
I don't have Solaris, but I can't imagine it would be much more than this:
./configure --prefix=/home/bob
make
make install
不需要root特权。
这篇关于unix-diff命令以单行/每行格式输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!