![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sort problem | talashil | Shell Programming and Scripting | 4 | 04-11-2008 04:56 PM |
| sort -k | Indalecio | Shell Programming and Scripting | 4 | 03-16-2007 04:00 AM |
| Sorting problem "sort -k 16,29 sample.txt > output.txt" | ganapati | Shell Programming and Scripting | 3 | 08-01-2006 06:55 AM |
| SORT problem on SUN | bobk544 | UNIX for Dummies Questions & Answers | 2 | 06-29-2006 04:46 PM |
| Problem with sort | jyoung | UNIX for Dummies Questions & Answers | 1 | 04-13-2006 01:57 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
how to use awk to sort this problem out
there has several numbers which are:1,2,3,45,6,7,8,9,0,10,34,34,54,122,6756,54,87,99,2,1,45;
how to write a shell script orts the above numbers into descending order and puts them into and arrray and also find and prints the minimum and maximum of those numbers, and finds and prints the average of the numbers. the outputs should be like: minimum number:2 maximum number:10 average:5 |
|
||||
|
why the max is 10 but not 6756 while the min is 1 but not 0.
If the requirement is what i assumed as above. Follow code can fullfill it. Code:
filename:b
awk 'BEGIN{RS=","}
{
print
}' b> c
sort -n c > c.t
rm c
sed '/^$/d' c.t > c
rm c.t
echo "min=`head -1 c`"
echo "max=`tail -1 c`"
echo "avg=`awk '{n=n+$0}END{print n/NR}' c`
|
![]() |
| Bookmarks |
| Tags |
| awk |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|