Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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,
#!/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;
gives the following output:
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.txt
Amimal, 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.....
BadFile.txt
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........

In reply to Re: compare two files and print the differences of file 2 in a third file by kevbot
in thread compare two files and print the differences of file 2 in a third file by hopper

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-24 18:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found