Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: divide multi-column input file into sub-files depending on specific column's value

by Anonymous Monk
on Jul 05, 2016 at 19:54 UTC ( [id://1167273]=note: print w/replies, xml ) Need Help??


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
  • Comment on Re: divide multi-column input file into sub-files depending on specific column's value
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1167273]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 15:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found