Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Column sort script

by mscharrer (Hermit)
on Aug 13, 2008 at 11:31 UTC ( #704065=CUFP: print w/ replies, xml ) Need Help??

Hi fellow monks,

I wrote a small script which sorts text files after the last column (i.e. lines are separated by a given separator).
I use it mainly to sort a list of file paths by file names ignoring directories names by calling it with '/' as separator:

csort / list.txt

It could be improved by adding some sorting order options, etc.

#!/usr/bin/perl # Usage: csort <separator> (<inputfiles> | < input) > output use strict; use warnings; my $sep = shift or die; # separator to use my @list; while (<>) { chomp; push @list, [ /\A (.*) $sep (.*)/x ]; } foreach my $aref ( sort { $a->[1] cmp $b->[1] or $a->[0] cmp $b->[0] } + @list ) { print join ($sep, @$aref), "\n"; }

Comment on Column sort script
Select or Download Code
Re: Column sort script
by artist (Parson) on Nov 15, 2008 at 02:09 UTC
    You can also user more elegant solution using File::Basename

    --Artist

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://704065]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2014-09-20 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (157 votes), past polls