I can't follow where Host/Device IP is cooming from. I guess this shows that you want to merge two csv files?
I never worked on Solaris 10, but why not looking for .tar.gz and then using tar xzf (or something like that) to extract? A second way if installed would be cpan. get module, make module, test module, install module.
Anyway, if you're able to extract one column, you just have to add the same part again in your loop by checking for another column ... you're creating an array or append on a string all your results (formatted) for both csv-files then writing a third loop printing into csv-file.
Following code is not tested and should be more like a kind of Pseudo Code
my @aColumns1; my @aColumns2; open ( my $sData, '<', $hFile ) or die "Could not open '$hFile' $!\n"; while ( my $sLine = <$sData> ) { chomp $sLine; my @aFields = split "," , $sLine; push ( @aColumns1, $aField[1] ); push ( @aColumns2, $aField[3] ); } close ( $hFile ); my @aColumns3; my @aColumns4; @aFields = ''; open ( $sData, '<', $hFile ) or die "Could not open '$hFile' $!\n"; while ( $sLine = <$sData> ) { chomp $sLine; @aFields = split "," , $sLine; push ( @aColumns3, $aField[2] ); push ( @aColumns4, $aField[4] ); } close ( $hFile ); open ( '>', $hFile ) or die "Could not open '$hFile' $!\n"; for (...) { print $hFile "$aColumns1[x];$aColumns2[x];$aColumns3[x];$aColumns4 +[x]\n"; } close ( $hFile );
If you would like you could probably use 2D-Arrays too.
Regards
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Extracting multiple column from csv file and adding/appending onto new csv file with first columns already existing
by Bloodnok (Vicar) on Apr 17, 2014 at 09:30 UTC | |
by Yaerox (Scribe) on Apr 17, 2014 at 09:38 UTC | |
by Bloodnok (Vicar) on Apr 17, 2014 at 09:45 UTC | |
by Yaerox (Scribe) on Apr 17, 2014 at 09:53 UTC |
In Section
Seekers of Perl Wisdom