#!//perl -w $startLineNum = 1; $stopLineNum = 1e20; if ($#ARGV < 2) { printf STDERR "$0 [] ... [] [-startStop startLineNum stopLineNum]\n"; exit(1); } $inputfile = shift(@ARGV); if (!open(INPUT,"< $inputfile")) { printf STDERR "error: cannot open file <%s> for read\n",$inputfile; exit(1); } $outputfile = shift(@ARGV); if (!open(OUTPUT,"> $outputfile")) { printf STDERR "error: cannot open file <%s> for write\n",$outputfile; exit(1); } $i = 0; while ($i <= $#ARGV) { if ($ARGV[$i] eq "-startStop") { $i++; $startLineNum = $ARGV[$i]; $i++; $stopLineNum = $ARGV[$i]; } else { push(@keepColumnList,$ARGV[$i]); } $i++; } $lineNum = 0; while () { $lineNum++; if (($lineNum >= $startLineNum) && ($lineNum <= $stopLineNum)) { if ($_ !~ m/^#/) { $_ =~ s/\n//; @token = split; if ($token[0] eq "") { shift(@token); } for ($i=0; $i<= $#keepColumnList; $i++) { print OUTPUT $token[$keepColumnList[$i]-1] . " "; } print OUTPUT "\n"; } else { print OUTPUT $_; } } } close(INPUT); close(OUTPUT); exit(0);