I am comparing 2 large CSV file using Perl that's called in a batch file. I put the result in a 3rd file.
Currently the file contains other information like headers, and other lines like this:
--- file1.txt Wed Mar 7 14:57:10 2018
+++ file2.txt Wed Mar 7 13:56:51 2018
@@ -85217,4 +85217,8 @@
How can the result file only contains the difference ? Thank you.
This is my perl:
#!/usr/bin/env perl
use strict; use warnings;
use Text::Diff;
my $diffs = diff 'file1.txt' => 'file2.txt';
print $diffs;
This is my batch file:
perl diffperl.pl > newperl.csv
In the unified format,
@
" indicate location of the differences in the file.-
" indicates a line that is only in the first file.+
" indicates a line that is only in the second file.\ No newline at end of file
".Solution:
Note that adding
CONTEXT => 0
will reduce the number of lines to remove.That said, there's not much point in using Text::Diff if you want your own output format. You might as well use Algorithm::Diff directly.
You should look at the
STYLE
option in the documentation for Text::Diff. It's possible that one of the built-in styles might be more to your liking. But if that's not the case you could write your own formatting package. It sounds to me like you would just need to supply ahunk_header()
method that returns an empty string (as it's the hunk header lines that you don't like).