Even so, now we're just talking about a two-stage sort:
where "splitter.pl" is a version of your suggested script that assumes lines are pre-sorted by output file name -- so it really needs only one output file handle open at any one time. By pre-pending the original line numbers before sorting, and using the line numbers as a secondary sort field, the (presumably) intended result is achieved.## let's suppose the file names are in column 3 of "table.txt": perl -pe 's/^/$.,/' table.txt | sort -t , -k 4,4 -k 1,1n | cut -f2- -d +, | splitter.pl
(update: if the original table has file names in column 3, and a perl script prepends a line number to each line, then the primary sort column has to be 4, not 3.)
In reply to Re^3: Performance Trap - Opening/Closing Files Inside a Loop
by graff
in thread Performance Trap - Opening/Closing Files Inside a Loop
by Limbic~Region
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |