in reply to divide multi-column input file into sub-files depending on specific column's value
Just write straight to the files:
#!/usr/bin/perl # http://perlmonks.org/?node_id=1167222 use strict; use warnings; my %files; while(<DATA>) { /(.*\S)\s+(\S+)/ or next; $files{abs $2} or open $files{abs $2}, '>', "output_@{[abs $2]}.txt" + or die; printf {$files{abs $2}} "%3d %3d %s\n", $2, $., $1; } close $_ for values %files; system 'more output_*.txt | cat'; # for debugging __DATA__ -59.077 89.301 115.664 7 -61.251 77.435 117.760 -6 -60.950 71.712 116.061 -7 -56.247 83.685 114.576 1 -59.263 76.107 112.555 -2 -59.895 65.296 111.185 3 -60.141 63.694 111.257 -3 -61.667 63.707 116.937 2 -58.722 60.429 111.307 -1 -57.511 42.922 112.108 6
|
|---|