in reply to Reorganizing the content of a file
Sigh. No one has done it with regexes yet, and that makes me sad. :)
#!/usr/bin/perl # https://perlmonks.org/?node_id=1227383 use strict; use warnings; local $_ = join '', sort { $a =~ s/.*,//r cmp $b =~ s///r } <DATA>; for my $id ( /^(\d+)/gm ) { print /^$id,.*,(\S+)/m; $id = $1, print ',', /^$id,.*,(\S+)/m while /^$id,(\d+)/m; print "\n"; } __DATA__ 15,10,name3 10,#,name1 12,10,name2 5,12,name4 8,5,name5
|
|---|