Need Perl script to compare two CSV files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need Perl script to compare two CSV files
# 8  
Old 03-16-2011
Here you go.

Code:
#!/usr/bin/perl

open(LK,"MsPMTP.csv") or die "$!\n";
open(DF,"ProfileNames.csv")  or die "$!\n";

while (<DF>) {
next if $. == 1;
chomp;
@flds=split(/,/);
$lookup{substr($flds[1],index($flds[1],"_"))}=$flds[0];
}
close(DF);

while(<LK>){
chomp;
if (exists $lookup{substr($_,index($_,"_"))}) {
print $lookup{substr($_,index($_,"_"))},",",$_,"\n";
} else {
print "No Profile,",$_,"\n";
}
}
close(LK);

# 9  
Old 04-05-2011
thank you very much it is woking fine, but one problem for Profile PM_AB only 4500 points only coming, actually it aroung 9000 point has to, is the any limitation in perl Arry
# 10  
Old 04-05-2011
To write a script to test anybody would need a small set of data to test. The files you have are so huge.

But any way try this.
Code:
#!/usr/bin/perl

open(DF,"ProfileNames.csv")  or die "$!\n";

while ($lin = <DF>) {
$col = +(split ",", $lin)[1];
  open(LK,"MsPMTP.csv") or die "$!\n";

  while($lin2 = <LK>){
   $col1 = +(split ",", $lin2)[0];
   if ($col =	$col1) {
     $ok = "Y";     
   } else {
   $ok = "N";   
   }

   if ($ok = "Y") {
     print $lin,"\n";
   } else {
     print "No Profile,",$lin,"\n";
   }
}
close(LK);


}
close(DF);


Last edited by Franklin52; 04-06-2011 at 04:05 AM.. Reason: Please use code tags, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need awk or Shell script to compare Column-1 of two different CSV files and print if column-1 matche

Example: I have files in below format file 1: zxc,133,joe@example.com cst,222,xyz@example1.com File 2 Contains: hxd hcd jws zxc cst File 1 has 50000 lines and file 2 has around 30000 lines : Expected Output has to be : hxd hcd jws (5 Replies)
Discussion started by: TestPractice
5 Replies

2. Shell Programming and Scripting

Script to compare count of two csv files

Hi Guys, I need to write a script to compare the count of two csv files each having 5 columns. Everyday a csv file is recived. Now we need to compare the count of todays csv file with yesterday's csv file and if the total count of records is same in todays csv file and yesterday csv file out... (3 Replies)
Discussion started by: Vivekit82
3 Replies

3. Shell Programming and Scripting

Perl script to Convert XLSX or XLS files to CSV file

Hi All, I've got in a situation where I need to convert .xlsx or .xls formatted files into simple text file or .csv file. I've found many options but doing this using PERL script is the best way I believe.I'm in AIX box. Perl code should have 2 params while running. i.e perl... (1 Reply)
Discussion started by: manab86
1 Replies

4. Shell Programming and Scripting

Compare 2 csv files in ksh and o/p the difference in a new csv file

(say) I have 2 csv files - file1.csv & file2.csv as mentioned below: file1.csv ID,version,cost 1000,1,30 2000,2,40 3000,3,50 4000,4,60 file2.csv ID,version,cost 1000,1,30 2000,2,45 3000,4,55 6000,5,70 The... (7 Replies)
Discussion started by: Naresh101
7 Replies

5. Shell Programming and Scripting

Perl script to compare two files

hi, As such I am new to perl on google search I found a code for Perl script to compare two files and print differences between them and instead of prinintg I want to store the diff. in a outputfile so can sombody provide assistance upon this from where can I edit in script to store the diff in... (1 Reply)
Discussion started by: dinesh.4126
1 Replies

6. Shell Programming and Scripting

Help with script to open and compare csv files

We are testing an application that accesses two tables: A and B. I am to write a script to validate the ouput files of this application.The application marks any account that has become overdue as per rule. When it runs, it updates the overdue flag in the A table according to the following rules: ... (1 Reply)
Discussion started by: inkyponky
1 Replies

7. Shell Programming and Scripting

Need to compare two csv files values and write into another csv file

Hi all, Am new to scripting. So i just need your ideas to help me out. Here goes my requirement. I have two csv files 1.csv 2.csv abc,1.24 abc,1 def,2.13 def,1 I need to compare the first column of 1.csv with 2.csv and if matches then need to compare... (2 Replies)
Discussion started by: chinnahyd
2 Replies

8. UNIX for Dummies Questions & Answers

How to compare csv files using perl

I need to compare 2 csv files and report should containg number of matching lines,different lines ,missing lines in one file using perl. I dont want to use read line by line and scan thru the second file for matching line ,as this logic was so time consuming .Can other ideas .please respond asap... (2 Replies)
Discussion started by: kittu1979
2 Replies

9. UNIX for Dummies Questions & Answers

Compare 2 csv files in perl

need to compare 2 csv files and report should containg number of matching lines,different lines ,missing lines in one file using perl. I dont want to use read line by line and scan thru the second file for matching line ,as this logic was so time consuming .Any ideas.i need the soultion badly .... (2 Replies)
Discussion started by: kittu1979
2 Replies

10. Shell Programming and Scripting

compare 2 coloum of 2 diff files using perl script

Hi, i am new to perl scripting.. i am still learing it.. i am asked to write a perl script which should compare 2 coloums of 2 different files. if those 2 coloumn are same the script should store the both the lines in 2 diff files. these are files, file 1: 21767016 226112 char 19136520... (3 Replies)
Discussion started by: vasuki
3 Replies
Login or Register to Ask a Question