The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Ascending & Descending order numbers pravani1 Shell Programming and Scripting 6 06-03-2008 04:43 AM
How to sort a string with numbers ahjiefreak Shell Programming and Scripting 5 12-21-2007 07:52 AM
Sort ascending and descending don_0110 UNIX for Dummies Questions & Answers 0 11-22-2007 07:36 AM
How to add numbers? pnxi Shell Programming and Scripting 7 09-11-2003 03:25 AM
Sort / ascending order gyik UNIX for Dummies Questions & Answers 1 03-05-2001 07:08 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 01-17-2007
Registered User
 

Join Date: Sep 2006
Location: Sg
Posts: 321
Sort Numbers in ascending orders

Hi All,

I am new to Shell programming. I have problems creating a csh script which can sort numbers in ascending orders using array.
For eg, given the following numbers: 8, 56, 15, 37, 21.
I would want the output to be in the following: 8,15,21,37,56.

Can anybody help me with this ?
Reply With Quote
Forum Sponsor
  #2  
Old 01-17-2007
Registered User
 

Join Date: Dec 2006
Location: Maryland
Posts: 144
cat filename | sort -kn1

I hv no idea to use arrays.
Reply With Quote
  #3  
Old 01-17-2007
Registered User
 

Join Date: Sep 2006
Location: Sg
Posts: 321
Hi Kap,

What does the -kn1 stand for ?
Reply With Quote
  #4  
Old 01-17-2007
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
$ echo "8,56,15,37,21" | tr ',' '\n' | sort -k1,1n | paste -s -d',' -
8,15,21,37,56

Cheers
ZB
Reply With Quote
  #5  
Old 01-18-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,580
If you have Python:
Code:
echo "8,56,15,37,21" | python -c "print sorted(map(int,raw_input().split(',')))"
output:
Code:
[8, 15, 21, 37, 56]
Reply With Quote
  #6  
Old 01-18-2007
Registered User
 

Join Date: Sep 2006
Location: Sg
Posts: 321
Hi ,

Can anybody tell me what does the syntax "tr" , "k1" , "1n" mean in the below code ?

echo "8,56,15,37,21" | tr ',' '\n' | sort -k1,1n | paste -s -d',' -
Reply With Quote
  #7  
Old 01-18-2007
blowtorch's Avatar
Supporter
 
Join Date: Dec 2004
Location: Singapore
Posts: 2,326
Do you have access to man pages? Can't you look these up there? Come on, the point of these forums is not to explain each and every command, is it?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:13 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0