in reply to Re: Tagging the differencies in both files
in thread Tagging the differencies in both files

And how would you handle two files which have the same lines but in a different sequence? Or when the files have multiple identical lines?

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics
  • Comment on Re^2: Tagging the differencies in both files

Replies are listed 'Best First'.
Re^3: Tagging the differencies in both files
by zentara (Cardinal) on Jun 17, 2012 at 19:42 UTC
    Thats why I left it to the OP, :-) , and remarked you would need to expand the hashes to contain all the line data per file. Just as an initial brainstorm, in addition to the hash where you count duplicates, you would have 2 other hashes with each line as key and $filename:linenumber as value. Then in a relatively complex logic loop, you would first find duplicates, then reloop thru each file, testing each line for duplicates, and comparing $filename:linenumbers thru the hash key searches. I'm sure with enough diligence it can be done, because all the information is available in the 3 hashes. Of course, that's just my first thoughts, someone else may know a sweeter way involving less logic. You could also look at tkdiff, it isn't perl tk, but it does color highlighting the way you desire.

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Thank you for your responses. But the question was answered in another forum. I also asked this question here: http://stackoverflow.com/questions/11070174/tagging-the-differencies-in-both-files and I got a good answer. the code below does the task that I want:
      diff --old-line-format "<Diff></Diff>%c'\012'" \ --new-line-format "<Diff>%l</Diff>%c'\012'" \ File1.txt File2.txt > NewFile1.txt diff --old-line-format "<Diff>%l</Diff>%c'\012'" \ --new-line-format "<Diff></Diff>%c'\012'" \ File1.txt File2.txt > NewFile2.txt