#!/usr/bin/perl#use strict;#use warnings;open my $CSV, '<', 'sample1.csv' or die "failed to open 'sample1.csv' $!";open my $TXT, '<', 'sample.txt' or die "failed to open 'sample.txt' $!";open my $NEW, '>', 'new1.csv' or die "failed to open 'new1.csv' $!";while(<$CSV>) { chomp; my @csv = split /,/; for ($i=20;$i<=30;$i++) { $csv[0]=$i;} my $phone = <$TXT>; chomp $phone; $csv[5] = $phone; no warnings; $i=$i+1; print $NEW join(',', @csv[0..12]) . "\n"; use warnings;}
i have one more favor to ask, how can i populate a csv file with the following values
org21,,,,,,0,,,20,,,
org22,,,,,,0,,,21,,,
org23,,,,,,0,,,22,,,
org24,,,,,,0,,,23,,,
org25,,,,,,0,,,24,,,
org26,,,,,,0,,,25,,,
..
..
..
org,,,,,,,,,0,,,k,,,
Basically column 0 or 1 should be org where i should be 21 or any number and the column 1's in the following column should be org similarly coloumn 7 should be always 0 and column 10 should be and the subsequent column 10's should be i+1.
The o/p is getting messed up as the following ,which is potentially due to the commas in the input file
,0,,org20,,,,,,,,,,,,,,,,,,,,,,,cs Finance.1
,0,,org20,,,,,,,,,,,,,,,,,,,,,,,ms.Risk Mgmt.1
,0,,org20,,,,,,,,,,,,,,,,,,,,,,,mt.1
org23,,,Adjuster, Sr Cargo Claims.Risk Mgmt.1,0,,org20,,,,,,,,,,,,,,,,,,,,,,,
Really would appreciate your help!
#!/usr/bin/perlopen my $TXT, '<', 'pos.txt' or die "failed to open 'pos.txt' $!";open my $NEW, '>', 'neworg.csv' or die "failed to open 'neworg.csv' $!";$i = 20;#$j=19; while(<$TXT>) { chomp; #my @TXT = split /,/; #index number for 'orgHeadUniqueName' $TXT[4] = 0; #index number for 'reportingHierarchyRootUniqueName' $TXT[6] = "org20"; #index number for 'uniqueName' $TXT[0] = "org".$i; $i++;# $j++; my $pos = <$TXT>; chomp $pos; #index number for 'displayName' for ex position code $TXT[3] = $pos; no warnings; print $NEW join(',', @TXT[0..29]) . "\n"; use warnings;}
for ($i=20;$i<=30;$i++) {
$csv[0]=$i;
}
just remove, and use $i out side of while starting with 20.
Open in new window