Hi, I am trying to compare two files which have content like
/dir1/file1
/dir1/file2
/dir1/file3

with another file which has content like
/dir2/file1
/dir2/file2
/dir2/file3

I need to compare each line in file tst1 with corresponding line in file tst2 and determine if they are same , that is find out if there is any difference in thier content , but i am ending up with errors ,compare file in tst1 and file 1 in tst2 , compare file2 in tst1 and file2 in tst2 and so on. could anyone pls help me as i am a very intermittent user of scripting
#! /usr/bin/perl open (IF,"<tst1"); open (IF2,"<tst2"); my(@tst1) = <IF>; my(@tst2) = <IF2>; my ($i); my ($j); foreach $i (@tst1) { chomp($i); print "$i\n"; foreach $j (@tst2) { chomp($j); print "$j\n"; `diff $i $j > /dev/null`; `echo $?`; } } close(IF); close(IF2);

In reply to compare two files line by line and perform a diff on each coressponding line by dilip_val

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.