![]() |
| ||
| Compare two Text File Hi, I have one perl script for comparing two text file entries. But its not working according to my expectation. Its comparing line by line, not like comparing one entry to the complete file. I like the script to be compare all the entries irrespective of line by line comparison. $f1 = 'E:\upload\new\2.txt'; open FILE1, "$f1" or die "Could not open file \n"; $f2= 'E:\upload\new\a.txt'; open FILE2, "$f2" or die "Could not open file \n"; $outfile = 'E:\upload\new\1.txt'; my @outlines; foreach (<FILE1>) { $y = 0; $outer_text = $_; seek(FILE2,0,0); foreach (<FILE2>) { $inner_text = $_; if($outer_text eq $inner_text) { $y = 1; print "$outer_text, Match found \n"; last; } } if($y != 1) { print "$outer_text,No Match Found \n"; push(@outlines, $outer_text); } } open (OUTFILE, ">$outfile") or die "Cannot open $outfile for writing \n"; print OUTFILE @outlines; close OUTFILE; close FILE1; close FILE2; Can anybody please help me to enhace the script. Thanks in advance Vinod |
| ||
| Re: Compare two Text File Please use [code][/code] tags when posting code. http://www.daniweb.com/techtalkforum...ment112-3.html If you're trying to determine which lines are common to both files, then perhaps an easier approach would be to look at the Unix ulilities - sort - diff - comm |
| ||
| Re: Compare two Text File Use a hash to compare the lines. use strict; There are also some perl modules that will compare files, or you can use the operating system commands Salem mentions. |
| ||
| Re: Compare two Text File Quote:
Example. File A------------------------File B uid=1------------------------uid=4 uid=2------------------------uid=3 uid=3------------------------uid=2 uid=4------------------------uid=1 uid=5 uid=6 In this case you can see file A is having all the values of file be, if we comapare file A with file B its showing "No Match". But i want the comparison like File A should match File B, as the value exist in File B. It will be good if you advice for the same. Thanks again Vinod |
| ||
| Re: Compare two Text File Didn't like my suggestion? |
| ||
| Re: Compare two Text File I think you should be able to pick your answer out of some combination of these commands. $ head xF* |
| All times are GMT -4. The time now is 1:28 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC