Hi shalgham,
Without removing anything from previous great post, I think ( that is if I get your question right ) what you need do is get the index of the column you wanted and print it out. Since all the values for the column you wanted follow the same.
Something like this, using a modified data given by InfiniteSilence
Output:#!/usr/bin/perl -l use warnings; use strict; # get the header into an array my @header = split /\s+/, <DATA>; # conjure a regex using the name of columns you wanted # which is the array you have my $to_find = join( '|' => qw(nat pls kac) ); my $reg_to_use = qr/$to_find/; # get the index of the header you need my @index = grep { $header[$_] =~ /$reg_to_use/ } 0 .. $#header; print join( "\t" => @header[@index] ); while (<DATA>) { print join( "\t" => ( split /\s+/, $_ )[@index] ); } __DATA__ nat pls fof tri pls fof tri kac 0.1 0.1 0.23 0.1 0.1 0.23 0.1 0.31 2.3 1.8 3.2 4.4 1.8 3.2 4.4 3.21 5.5 3.2 8.6. 7.9 3.2 8.6. 7.9 2.89
Note: I don't know how your real dataset looks like, and the above 'might' not be the best in your situation but I can only hope this gives a head up.nat pls pls kac 0.1 0.1 0.1 0.31 2.3 1.8 1.8 3.21 5.5 3.2 3.2 2.89
In reply to Re: searching an array member in file header and print a column
by 2teez
in thread searching an array member in file header and print a column
by shalgham
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |