All pastes #341781 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-02-05 21:25 UTC
rendered paste body
#!/usr/local/bin/perl

my $sort_col = 3;

my @output = 
sort {
    (split ',', $a)[$sort_col - 1] cmp
    (split ',', $b)[$sort_col - 1]
} <DATA>;

print for @output;

__DATA__
0,115608,2,3237821,0,0
0,115612,1,3237825,0,0
1,115612,0,3237825,0,0
0,115612,1,3237825,0,0
0,115616,2,3237829,0,0
0,115616,2,3237829,0,0
0,115616,2,3237829,0,0

output:
1,115612,0,3237825,0,0
0,115612,1,3237825,0,0
0,115612,1,3237825,0,0
0,115608,2,3237821,0,0
0,115616,2,3237829,0,0
0,115616,2,3237829,0,0
0,115616,2,3237829,0,0