Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Comparison Of Files

by decnartne (Beadle)
on Dec 05, 2000 at 20:43 UTC ( [id://45013]=note: print w/replies, xml ) Need Help??


in reply to Comparison Of Files

if you have no aversion to diff, how about:

#!/usr/bin/perl -w use strict; open(INP, "/usr/bin/diff ./newsite1.txt ./newsite2.txt |") or die "pip +e: $!\n"; while (<INP>) { print substr($_,2) if (/^> /); print substr($_,2) if (/^< /); } close(INP);

decnartne ~ entranced

Replies are listed 'Best First'.
(tye)Re2: Comparison Of Files
by tye (Sage) on Dec 05, 2000 at 20:49 UTC

    Two problems. First, you may need to sort both files before you do this. If the order of entries might change between days, then "diff" isn't a great solution.

    Second, you'll probably end up printing severals lines as being both added and deleted. "diff" isn't great at doing a set difference. It is looking for document edits and so can easily report a big chunk of the "bigger" file as being changed and then show the subset of that chunk that was already there in the "smaller file" (and didn't change).

            - tye (but my friends call me "Tye")
      The 2 files are created from a directory listing of all the sites in the system, soi they will automatiicaly be sorted, in exactly the same order, however, new sites will be placed within that order. So the files could look like this:
      newsite1:
      PHI_R10K_2 PHI_TDAP_3 de0040Newark de0042Wilmington de0053Christana de0053Christiana de0101Odessa de0102Clayton de0103Dover de0180Claymont de0184Wooddale de0187Woodcreek de0205ChestnutKnoll de0267Chapman de0314Glasgow de0348Millside de0371SouthDover
      newsite2:
      PHI_R10K_2 PHI_TDAP_3 de0040Newark de0042Wilmington de0045Concord # <======= new site de0053Christana de0053Christiana de0101Odessa de0102Clayton de0103Dover de0180Claymont de0184Wooddale de0187Woodcreek de0205ChestnutKnoll de0267Chapman de0314Glasgow de0348Millside de0371SouthDover
      at which point i would want de0045concord returned.
      I hope this helps.
      Thanks again


      Dipul
      ouch! you're right... i did some further testing, and let's just say it's pretty ugly...

      decnartne ~ entranced

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://45013]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found