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 > 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 and shell scripting languages here.

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

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

Join Date: Sep 2006
Location: Sg
Posts: 350
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 ?
  #2 (permalink)  
Old 01-18-2007
kapilraj kapilraj is offline
Registered User
  
 

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

I hv no idea to use arrays.
  #3 (permalink)  
Old 01-18-2007
Raynon Raynon is offline
Registered User
  
 

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

What does the -kn1 stand for ?
  #4 (permalink)  
Old 01-18-2007
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
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
  #5 (permalink)  
Old 01-18-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
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]
  #6 (permalink)  
Old 01-18-2007
Raynon Raynon is offline
Registered User
  
 

Join Date: Sep 2006
Location: Sg
Posts: 350
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',' -
Closed Thread

Bookmarks

Tags
awk, awk trim, trim, trim awk

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 02:29 PM.


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