in reply to divide multi-column input file into sub-files depending on specific column's value
This does what you asked for in the first screenful of your post. I wrote and tested it before noticing there was a lot more to the post, so here it is, maybe it is useful to you:
#! perl -sw use strict; my %fhs; while( <DATA> ) { my @bits = split; my $abs = abs( $bits[ 3 ] ); open $fhs{ $abs }, '>', 'output_' . $abs or die $! unless exists $ +fhs{ $abs }; print { $fhs{ $abs } } $_; } __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
Produces:
C:\test>type output_* output_1 -56.247 83.685 114.576 1 -58.722 60.429 111.307 -1 output_2 -59.263 76.107 112.555 -2 -61.667 63.707 116.937 2 output_3 -59.895 65.296 111.185 3 -60.141 63.694 111.257 -3 output_6 -61.251 77.435 117.760 -6 -57.511 42.922 112.108 6 output_7 -59.077 89.301 115.664 7 -60.950 71.712 116.061 -7
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: divide multi-column input file into sub-files depending on specific column's value
by angela2 (Sexton) on Jul 05, 2016 at 11:08 UTC | |
by BrowserUk (Patriarch) on Jul 05, 2016 at 14:37 UTC | |
by angela2 (Sexton) on Jul 05, 2016 at 15:50 UTC | |
by AnomalousMonk (Archbishop) on Jul 05, 2016 at 16:34 UTC | |
by BrowserUk (Patriarch) on Jul 05, 2016 at 16:11 UTC | |
by angela2 (Sexton) on Jul 05, 2016 at 16:23 UTC | |
|