here is a rather simple formulation of an approach. I leave it to you to get the formatting right and put in the appropriate file opens... $. is line number of current file.
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my %hash; # make a hash of array based upon last column while (my $line = <DATA>) { my @tokens = split ' ', $line; my $abs_lastcol = abs $tokens[-1]; my $newline = "$tokens[-1] $. $tokens[0] $tokens[1] $tokens[2]"; push @{$hash{$abs_lastcol}}, $newline; } foreach my $file (sort keys %hash) { print "generate file: $file...\n"; print "$_\n" for @{$hash{$file}}; } =prints generate file: 1... 1 4 -56.247 83.685 114.576 -1 9 -58.722 60.429 111.307 generate file: 2... -2 5 -59.263 76.107 112.555 2 8 -61.667 63.707 116.937 generate file: 3... 3 6 -59.895 65.296 111.185 -3 7 -60.141 63.694 111.257 generate file: 6... -6 2 -61.251 77.435 117.760 6 10 -57.511 42.922 112.108 generate file: 7... 7 1 -59.077 89.301 115.664 -7 3 -60.950 71.712 116.061 =cut __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

In reply to Re: divide multi-column input file into sub-files depending on specific column's value by Marshall
in thread divide multi-column input file into sub-files depending on specific column's value by angela2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.