Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by bichonfrise74 (Vicar)
on Oct 21, 2009 at 23:18 UTC ( #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
Node Status?
node history
Node Type: note [id://802563]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2018-06-23 16:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (125 votes). Check out past polls.

    Notices?