简体   繁体   English

sed / awk-比较文件,并返回具有差异的行

[英]sed/awk - compare files, and return lines that have differences

I have two files 我有两个档案

file1: 文件1:

1
2
3
4
5
6

file2: 文件2:

1
2a
3
4
5
6a

How can I script something that will return a third file that will output the lines that are different, along with the line number and filename? 如何编写脚本以返回第三个文件,该文件将输出不同的行以及行号和文件名? Ie. IE浏览器。 as lines 2 and 6 are different, the output is something like this, with a filename of 'file3': 由于第2行和第6行不同,因此输出类似于以下内容,文件名为'file3':

file3 文件3

file1;line 2;2
file2;line 2;2a
file1;line 6;6
file2;line 6;6a

Thankyou as always! 一如既往的谢谢!

Probably you are looking for diff command 可能您正在寻找diff命令

type man diff on your shell for more detials 在您的shell上输入man diff以获得更多细节

There are diff command as jkshah said. 就像jkshah所说的diff命令。 And there are too vimdiff tool. 而且也有vimdiff工具。

If it's for occasional analysis and not to encapsulated in a script, vimdiff is very pleasant to use (using vim therefore allows access to vim commands such as search by regex, but also the syntax highlighting ...). 如果仅用于偶尔分析而不是封装在脚本中, vimdiff会非常好用(因此,使用vim可以访问vim命令,例如通过正则表达式进行搜索,还可以突出显示语法...)。 In other words, with vimdiff you have a better visual diff. 换句话说,使用vimdiff可以得到更好的视觉效果。

vimdiff file1 file2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM