in reply to compare two files and print the differences of file 2 in a third file
Hello lonnie,
I'm not sure that I completely understand your example. The data in GoodFile.txt and BadFile.txt differ on line 2, so I would expect that difference to show up in Output.txt. However, in your example it does not.
Here is some code that uses Algorithm::Diff to calculate the diff, with some help from Path::Tiny to get the file contents.
This code,gives the following output:#!/usr/bin/env perl use strict; use warnings; use Path::Tiny; use Algorithm::Diff qw/diff/; my @lines1 = path('GoodFile.txt')->lines; my @lines2 = path('BadFile.txt')->lines; my $diff = Algorithm::Diff->new( \@lines1, \@lines2 ); while( $diff->Next() ){ next if $diff->Same(); print $diff->Items(2), "\n"; } exit;
This section is the description of the animal bla bla lbas.....bla bla + lbas..... Amimal, cat, 3, 4, YELLOW LEG 3, HIGH 'this is a cattt 1 This section is the description of the animal bla bla lbas.....bla bla + lbas blaaaal........
UPDATE: The OP made edits to their node, and removed their input data. Here is the input data that I used for my code example (which the OP had provided in the first version of their post).
GoodFile.txtBadFile.txtAmimal, cat, 1, 4, YELLOW HAIR 3, HIGH 'this is a cattt 1 This section is the description of the animal bla bla lbas..... Amimal, dog, 2, 4, BLACK HEAD 1, HIGHf'this is a doggg 2 This section is the description of the animal bla bla lbas.....
Amimal, cat, 1, 4, YELLOW HAIR 3, HIGH 'this is a cattt 1 This section is the description of the animal bla bla lbas.....bla bla + lbas..... Amimal, cat, 3, 4, YELLOW LEG 3, HIGH 'this is a cattt 1 This section is the description of the animal bla bla lbas.....bla bla + lbas blaaaal........
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: compare two files and print the differences of file 2 in a third file
by hopper (Novice) on Jun 15, 2017 at 20:57 UTC | |
by kevbot (Vicar) on Jun 16, 2017 at 05:56 UTC |
In Section
Seekers of Perl Wisdom