Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Extracting selected column names and values from tab delimited text file

by bichonfrise74 (Vicar)
on Oct 21, 2009 at 23:18 UTC ( [id://802563]=note: print w/replies, xml ) Need Help??


in reply to Extracting selected column names and values from tab delimited text file

Here's something to get you started. Hopefully you can find this helpful.
#!/usr/bin/perl use strict; my @required_cols = qw( colname1 colname3 colname4 ); my %record; while (<DATA>) { my (@temp_data) = split( /\s+/ ); push( @{ $record{$_} }, $temp_data[$_] ) for (0 .. $#temp_data); } my (%final_data, $count); for my $i ( keys %record ) { $count = 0; for my $j ( @{ $record{$i} } ) { push( @{ $final_data{$count} }, $j ) if ( grep /\b$record{$i}->[0]\b/, @required_cols ); $count++; } } print "@{ $final_data{$_} }\n" for ( sort keys %final_data ); __DATA__ colname1 colname2 colname3 val1 val2 val3 val11 val21 val31 val12 val22 val32
  • Comment on Re: Extracting selected column names and values from tab delimited text file
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://802563]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-25 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found