Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vimdiff

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

you really need to see the picture

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!

like image 369
Javed Ahamed Avatar asked Nov 23 '25 22:11

Javed Ahamed


1 Answers

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
like image 81
richq Avatar answered Nov 27 '25 08:11

richq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!