Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: Extracting multiple column from csv file and adding/appending onto new csv file with first columns already existing by Yaerox
in thread Extracting multiple column from csv file and adding/appending onto new csv file with first columns already existing by bks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found