The UNIX Forums
"Join the Network of UNIX System Users"


 
Subject: sorting data based on multi columns
1mak
Newbie
Rank: 1



UID 29
Digest Posts 0
Credits 0
Posts 8
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 6, 2007 09:15 AM  Profile | P.M. 
sorting data based on multi columns



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


Top
 

 

All times are GMT, the time now is Jul 31, 2010 03:25 AM

Powered by Discuz! 5.0.0  © 2001-2006 UNIX Forums
Processed in 0.004523 second(s), 8 queries

Clear Cookies - Contact Us - UNIX Help - Archiver - WAP