UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 7th, 2005, 06:06 PM
snowmen snowmen is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 2 snowmen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 56 sec
Reputation Power: 0
Help on sort in Unix

Hi all,

I am a new user on this forum. nice to meet u all.
I am a newbie on Unix and current having problem to solve my problem with the sort command.

I have a file with 2 columns as the following:
0001 0012
0002 0089
0003 1234
0001 4567
0008 2456
0003 0028
0001 1011
0002 1112

I want to sort the first column in ascending order and then within the sorted first column, sort the second column in descending order.
The following is the desire output:
0001 4567
0001 1011
0001 0012
0002 1112
0002 0089
0003 1234
0003 0028
0008 2456

Can anyone help me please? any help is appreciated.
Thanks, Cheers

Reply With Quote
  #2  
Old August 7th, 2005, 06:28 PM
snowmen snowmen is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 2 snowmen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 56 sec
Reputation Power: 0
Oh, i have solved the problem.
For the sake of any new Unix user, like me, might want to know.
Here is the solution I used.

I solved it with multiple keydef (the -k option)

the command is:
sort -k 1,1 -k 2,2r infile.txt

this sorts the first column first, and then sorts the 2nd column in reverse order.

Cheers

Reply With Quote
  #3  
Old August 8th, 2005, 03:50 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,098 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 Days 7 h 51 m 27 sec
Reputation Power: 9
what ??

Quote:
Originally Posted by snowmen
Oh, i have solved the problem.
For the sake of any new Unix user, like me, might want to know.
Here is the solution I used.

I solved it with multiple keydef (the -k option)

the command is:
sort -k 1,1 -k 2,2r infile.txt

this sorts the first column first, and then sorts the 2nd column in reverse order.

Cheers


????????????????? what does:
sort -k 2,2r infile.txt

-k 2,2r IGNORES -k 1,1
__________________
working on Solaris[5-9], preferred languages french and C.

Reply With Quote
  #4  
Old August 8th, 2005, 08:11 AM
zlutovsky zlutovsky is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Prague, Czech Rep.
Posts: 117 zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level)zlutovsky User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 22 h 42 m 44 sec
Reputation Power: 6
Quote:
Originally Posted by guggach
????????????????? what does:
sort -k 2,2r infile.txt

-k 2,2r IGNORES -k 1,1


Sorry again, sheriff, you are barkling up the mistaken tree.

I have tried the snowmen's suggestion on Solaris and on AIX. On both systems is it OK.

Show us YOUR ORIGINAL solution please.

Congratulations! You have another post. You will get a better belt color. But the belt color does not say anythig about the bearer's quality.

Regards

Reply With Quote
  #5  
Old August 10th, 2005, 07:50 PM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,098 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 Days 7 h 51 m 27 sec
Reputation Power: 9
Sorry again, sheriff, you are barkling up the mistaken tree.

I have tried the snowmen's suggestion on Solaris and on AIX. On both systems is it OK.

Show us YOUR ORIGINAL solution please.

Congratulations! You have another post. You will get a better belt color. But the belt color does not say anythig about the bearer's quality.

OK
it works perfectly
so does
cat abc | lpr
i believe you dont see the difference, i would try
lpr abc

remarque
cat abc ABC | lpr
is really NOT the same
please stop your st... remarques

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Help on sort in Unix


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT