The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sorting based on Multiple columns dharmesht Shell Programming and Scripting 15 05-13-2009 10:44 AM
Removing lines that are (same in content) based on columns adsforall UNIX for Dummies Questions & Answers 7 11-09-2007 12:13 PM
Sorting based on columns MobileUser Shell Programming and Scripting 7 04-11-2007 02:03 PM
sorting file content on columns marshmallow UNIX for Dummies Questions & Answers 2 01-04-2007 12:10 PM
sorting a file with multiple columns outtacontrol UNIX for Dummies Questions & Answers 3 07-26-2006 01:51 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-15-2007
sumeet sumeet is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 33
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
  #2 (permalink)  
Old 02-15-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,723
Code:
sort -t ',' -k1.1,1.8 -k3.1,3.2 file
  #3 (permalink)  
Old 02-15-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
sort -t"," -k1.1,1.6 -k3n file
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0