Exemplo usando Perl
removeCols.pl:
#!/usr/bin/perl
my $file1="input.tsv";
my $file2="remove.txt";
open RFILE, $file2;
@cols=<RFILE>;
open INPUT, $file1;
#read header line, save indicies
my @header = split( /\t/, <INPUT> );
for my $i (0..$#header){
if (grep(/$header[$i]/, @cols)){
push @idx,$i;
$header[$i] = undef;
}
}
print join("\t",grep(defined,@header));
# loop remaining file
while(<INPUT>){
my @line = split(/\t/, $_);
$line[$_] = undef for (@idx);
print join("\t",grep(defined,@line));
}
linha de comando é executada como tal:
prompt> perl removeCols.pl