![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | 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 ? |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
cat filename | sort -kn1
I hv no idea to use arrays. |
|
#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 |
|
#5
|
|||
|
|||
|
If you have Python:
Code:
echo "8,56,15,37,21" | python -c "print sorted(map(int,raw_input().split(',')))"
Code:
[8, 15, 21, 37, 56] |
|
#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',' - |
|
#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?
|
||||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|