|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 ? |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
cat filename | sort -kn1
I hv no idea to use arrays. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Hi Kap,
What does the -kn1 stand for ? |
|
#4
|
||||
|
||||
|
$ echo "8,56,15,37,21" | tr ',' '\n' | sort -k1,1n | paste -s -d',' -
8,15,21,37,56 Cheers ZB |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
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] |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
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',' - |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
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?
|
| Sponsored Links | ||
|
![]() |
| Tags |
| awk, awk trim, trim, trim awk |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ascending and descending sort | Fafa | Shell Programming and Scripting | 3 | 06-25-2010 12:03 PM |
| Arbitrary sort orders | treesloth | UNIX for Dummies Questions & Answers | 2 | 06-17-2010 11:13 AM |
| Sort ascending and descending | don_0110 | UNIX for Dummies Questions & Answers | 1 | 11-27-2008 02:59 PM |
| Ascending & Descending order numbers | pravani1 | Shell Programming and Scripting | 6 | 06-03-2008 07:43 AM |
| Sort / ascending order | gyik | UNIX for Dummies Questions & Answers | 1 | 03-05-2001 09:08 AM |
|
|