sorting data based on multi columns
Hi all
I have data in following format:
CSCH74,2007,1,09103,15
CSCH74,2007,10,09103,0
CSCH74,2007,11,09103,0
CSCH74,2007,12,09103,0
CSCH74,2007,2,09103,15
CSCH74,2007,3,09103,194
CSCH74,2007,4,09103,115
CSCH74,2007,5,09103,66
CSCH74,2007,6,09103,0
CSCH74,2007,7,09103,0
CSCH74,2007,8,09103,0
CSCH74,2007,9,09103,0
CSCS74,2007,1,09103,142
CSCS74,2007,10,09103,0
CSCS74,2007,11,09103,0
CSCS74,2007,12,09103,0
CSCS74,2007,2,09103,1224
CSCS74,2007,3,09103,1332
CSCS74,2007,4,09103,1169
CSCS74,2007,5,09103,195
CSCS74,2007,6,09103,0
CSCS74,2007,7,09103,0
CSCS74,2007,8,09103,0
CSCS74,2007,9,09103,0
I want to sort it so that output is ( basically sort on column1 and 3)
CSCH74,2007,1,09103,15
CSCH74,2007,2,09103,15
CSCH74,2007,3,09103,194
CSCH74,2007,4,09103,115
CSCH74,2007,5,09103,66
CSCH74,2007,6,09103,0
CSCH74,2007,7,09103,0
CSCH74,2007,8,09103,0
CSCH74,2007,9,09103,0
CSCH74,2007,10,09103,0
CSCH74,2007,11,09103,0
CSCH74,2007,12,09103,0
CSCS74,2007,1,09103,142
CSCS74,2007,2,09103,1224
CSCS74,2007,3,09103,1332
CSCS74,2007,4,09103,1169
CSCS74,2007,5,09103,195
CSCS74,2007,6,09103,0
CSCS74,2007,7,09103,0
CSCS74,2007,8,09103,0
CSCS74,2007,9,09103,0
CSCS74,2007,10,09103,0
CSCS74,2007,11,09103,0
CSCS74,2007,12,09103,0
I have tried :
sort -t, +2 -3 +0 -1 file
sort -t, -k3,3 n -k1,1 file
sort -t"," -k3,3 n -k1,1 file
result is not what I wanted
CSCH74,2007,1,09103,15
CSCS74,2007,1,09103,142
CSCX74,2007,1,09103,28
CSYH74,2007,1,09103,57
CSYS74,2007,1,09103,165
CSYX74,2007,1,09103,11
D13H41,2007,1,08475,5
D13H42,2007,1,08475,43
D13H62,2007,1,08475,1
D13H81,2007,1,08475,12
D13L41,2007,1,08475,0
sort -t, -k1,1 -k3,3 n file
sort -t"," -k1,1 -k3,3 n file
sort -t"," -k 1,1 -k 3,3 n file
for all the above command the output is same as input file with statement cannot open 'n' and in last case cannot open -k 3,3 and n.
sort -t, -k1,1 -k3,3 -n file (comes up with usage of sort command)
nothing seems to work. any help from Unix Gurus is appreciated.
Thanks
Sumeet