Vimdiff - How to extract similar lines in files and output them to a file

自闭症网瘾萝莉.ら 提交于 2019-12-18 09:18:59

问题


I am new to vimdiff and had a question about outputting the similarities of the two or more files into a new file. For example, based on the following picture I would like to have b,c,e,f,a along with the names of the two files being compared outputted to a different file.

An example file template for this might be:

[file1's name][file2's name]

lines that were similar between both files

Is there any built in vim command to do this or some bash script I could write that would be able to extract the data needed from vim? Thank you in advance!


回答1:


You could use regular diff to get the output if you have it installed:

diff  --unchanged-line-format='%L' --old-line-format='' \
  --new-line-format='' a.txt b.txt

You would run that from the command line on Linux. Or from within Vim you would run it by typing :! first as follows:

:!diff  --unchanged-line-format='%L' --old-line-format='' \
  --new-line-format='' a.txt b.txt


来源:https://stackoverflow.com/questions/1059848/vimdiff-how-to-extract-similar-lines-in-files-and-output-them-to-a-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!