I have a file like this...
2183842512010-11-25 15379043 453130325
2386225062010-11-30 4946518 495952336
2386225062010-11-30 4946518 495952345
2386225062010-11-25 262066688 -516224026
2679350512010-11-25 262066688 -516224124
3196089062010-11-25 262066688 203238229
3447672592010-11-25 262066688 -516224128
3902366362010-11-25 262066688 -516224276
I wantr to sort the file based on two fields :-
a) first field position -- 1 to 9
218384251
238622506
b) second field position -- 10 to 19
2010-11-25
2010-11-30
i tried using sort -k1,9 -k10,19 file_name but i didn't get any output
Experts pls provide your inputs..
system
2
sort -k1,9 file | sort -k10,19
Scott
3
sort -k1.1,1.9 -k1.10,1.19 file
my @arr=<DATA>;
print map {$_->[2]} sort {$a->[0]<=>$b->[0] || $a->[1]<=>$b->[1]} map {my($a,$b,$c,$d)=$_=~/^(.{9})(.{4})-(.{2})-(.{2})/;[$a,$b.$c.$d,$_];} @arr;
__DATA__
2183842512010-11-25 15379043 453130325
2386225062010-11-30 4946518 495952336
2386225062010-11-30 4946518 495952345
2386225062010-11-25 262066688 -516224026
2679350512010-11-25 262066688 -516224124
3196089062010-11-25 262066688 203238229
3447672592010-11-25 262066688 -516224128
3902366362010-11-25 262066688 -516224276
I don't think splitting the first field affects the sort order in this case...
sort -k1,1 infile