So this is the files that i have. File 1 has like 400+ lines while file2 has only 200+ lines. I store column1 in file2 as key and the rest as values. I wanted to output the file as below by copying the lines that are present in file 2 and file 1.
File1: Item,Time,Pattern ,Attributes,From an_en11,200.00,{0 133},{ } br_gh13,140.09,{0 59},{ } ce_oy74,300.05,{0 230},{int_43} dt_pp50,200.11,{0 122},{ } er_tk02,305.47,{0 220},{ } ef_yb41,200.05,{0 233},{ } File2: Item,Sink,Buffer,Cell,Slew,Path,Violation,Area dt_pp50,0,0,2,0.000,0.000,0,0.000 er_tk02,0,2,3,0.002,0.004,0,0.001 ef_yb41,0,1,5,0.000,0.000,0,0.000 Output : Item,Sink,Buffer,Cell,Slew,Path,Violation,Area,Time dt_pp50,0,0,2,0.000,0.000,0,0.000,200.11 er_tk02,0,2,3,0.002,0.004,0, 0.001,305.47 ef_yb41,0,1,5,0.000,0.000,0,0.000,200.05
So this is the code that I had generate but when I run it, it says that the $keys,$value1,$value2 and $value3 are not initialized. Anyone know how to fix this?
my %file1Hash; my $value4; open my $file1, "<","design.rpt.csv" or die $!; open my $file2, "<","summary.rpt.csv"or die $!; open my $outfile_1, ">", "combined.rpt.csv" or die $!; while(<$file1>){ my($line) = $_; chomp $line; my($key,$value1,$value2,$value3) = $line =~ /(\w+),(\d+.\d+),(.\d+ +\s+\d+.\d+.)/g; $value4 = "$value1,$value2,$value3,"; push @{$file1Hash{$key}}, $value4; } while(<$file2>){ my ($line) = $_; chomp $line; my($key,$value1,$value2,$value3,$value4,$value5,$value6,$value7) = + $line =~ /(\w+|\S+),(\d+),(\d+),(\d+),(\d+.\d+),(\d+.\d+),(\d+),(\d+ +.\d+)/g ; if (exists $file1Hash{$key}) { print $file1Hash{$key}.",".$line."\n"; } else { # print $line."\n"; } } close $file1; close $file2; close $outfile_1; exit 0;
I don't know what is the problem and how to solve this. Please Help.
In reply to Combining Files using Hash by chaney123
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |