$ a2p 11121118.awk #!/usr/bin/perl eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if $running_under_some_shell; # this emulates #! processing on NIH machines. # (remove #! line above if indigestible) eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift; # process any FOO=bar switches $FS = ' '; # set field separator $, = ' '; # set output field separator $\ = "\n"; # set output record separator $FS = "\t"; line: while (<>) { chomp; # strip record separator @Fld = split($FS, $_, -1); if (($.-$FNRbase) == 1) { @Fields = split($FS, '', -1); # clear fields array for ($i = 1; $i <= ($#Fld+1); $i++) { $Fields[($i)-1] = $Fld[$i]; } next line; } for ($i = 1; $i <= ($#Fld+1); $i++) { &Pick('>', $Fields[($i)-1]) && (print $fh $Fld[$i]); } } continue { $FNRbase = $. if eof; } sub Pick { local($mode,$name,$pipe) = @_; $fh = $name; open($name,$mode.$name.$pipe) unless $opened{$name}++; }