gsvs36
New User
Mar 29, 2009, 12:34 AM
Post #1 of 2
(544 views)

WORK WITH 2 TO 3 TXT FILES

Can't Post


I am a beginer in perl, please help me. I have 2 files a.txt b.txt a.txt like this 5610,MCDOWELLN,50 5236,JPASSOCIAT,50 5236,KFA,500 5236,MLL,500 5590,DCW,300 b.txt like this 5234,ZEEL,EQ,1000 5236,JPASSOCIAT,EQ,500 5236,SUZLON,EQ,500 5236,ZEEL,EQ,250 5237,MEGH,EQ,15 5970,IBSEC,EQ,100 5970,SYNDIBANK,EQ,100 5970,VISHALEXPO,EQ,35000 In the out put i want 1.match $a2,$b2 next if $a1 and $a2 same then total $a3+$b4 2.all from a.txt except above match 3.all from b.txt except above match like this 5610,MCDOWELLN,50 5236,JPASSOCIAT,550 5236,KFA,500 5236,MLL,500 5590,DCW,300 5234,ZEEL,EQ,1000 5236,SUZLON,EQ,500 5236,ZEEL,EQ,250 5237,MEGH,EQ,15 5970,IBSEC,EQ,100 5970,SYNDIBANK,EQ,100 5970,VISHALEXPO,EQ,35000 my code is #!/usr/bin/perl w open (A,"<a.txt"); open (B,"<b.txt"); while (<A>){ chomp; ($a1,$a2,$a3)=split(/,/); seek B,0,0; while (<B>){ chomp; ($b1,$b2,$b3,$b4)=split(/,/); if ($a2 eq $b2){ print "$a1,$a2,$a3\n"; if ($a1 eq $b1){ $q= ($a3+$b4); print "$a1,$a2,$q\n"; }}}} close A; close B; but it not giving correct one .please help me
