in reply to creating smaller files from one large one
Or with 5.10+,perl -ple's/^(\S+\s+\S+).*/$1/' infile > outfile
perl -ple's/^\S+\s+\S+\K//' infile > outfile
Filter through the following to remove the header line:
perl -ne'print if $.>1'
Update: ah, you don't want to lose the extra columns, oops!
chomp( my $header = <> ); my @headers = $header =~ /\S+/g; my @fhs; for (@headers) { my $qfn = "$_.dat"; open(my $fh, '>', $qfn) or die("Can't create file \"$qfn\": $!\n"); push @fhs, $fh; } while (<>) { chomp; my @fields = split(/\s+/, $_); for (0..$#fhs) { printf({ $fhs[$_] } "%s %s\n", $fields[$_*2 + 0], $fields[$_*2 + 1], ); } }
|
|---|