compare 2 text files

Discussion in 'Programming' started by ssimon171078, May 5, 2011.

  1. #1
    i need to compare 2 text files and find data in file2 that no present in text file1.
    problem how find diffirences between files.
    i start write in perl:

    #!/usr/bin/perl -w
    open(SALES,"text1.txt");
    open(SALES2,"text2.txt");

    while (($line= <SALES>)&&($line2= <SALES2>))

    {
    print $line2;
    }
    close SALES;
     
    ssimon171078, May 5, 2011 IP
  2. mygold

    mygold Peon

    Messages:
    1,164
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Where is your files, can i see these anyway?
     
    mygold, May 7, 2011 IP
  3. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #3
    There are several Perl modules that do comparisons. Check CPAN.
     
    rainborick, May 7, 2011 IP
  4. om39a

    om39a Peon

    Messages:
    287
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    There are tools available for doing it... I wonder why you need a code to compare it.

    A sample code Synopses
    	use File::Compare;
    	if (compare("file1","file2") == 0) {
    	    print "They're equal\n";
    	}
    Code (markup):
     
    om39a, May 7, 2011 IP
  5. Dhamodharan

    Dhamodharan Peon

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    try it on if else condition or String functions( Concatenate, Compare, Upper Case, Lower Case)
     
    Dhamodharan, Jun 16, 2011 IP