Help with printing sorted array of numbers


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with printing sorted array of numbers
# 1  
Old 05-02-2011
Help with printing sorted array of numbers

Dear All,
I am trying to sort an array of numbers to retrieve the mimimum and maximum values of numbers in that array, by printing the first and last elements of the sorted array. My code is
Code:
  @sorted_numbers = sort (@numbers);
  print "@sorted_numbers\n";
  print "$sorted_numbers[0], $sorted_numbers[-1]\n";

For an example I am getting this with the above code
Code:
15657 327 385 673 683 823
15657, 5

and I'd like to get
Code:
327 385 673 683 823 15657
327, 15657

Can someone enligten on this and how to achieve the above result?
Cheers
Smilie

---------- Post updated at 09:21 AM ---------- Previous update was at 09:10 AM ----------

Thanks I already figured it out using
Code:
{ $a <=> $b }

Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate sorted awk array for further processing

Hello to all, I have and input file like this: Objects (id: bounding-box centroid area mean-color): 0: 800x800+0+0 406.6,390.9 378792 srgb(0,0,0) 11: 240x151+140+624 259.5,699.0 36240 srgb(255,255,255) 6: 240x151+462+176 581.5,251.0 36240 srgb(255,255,255) 7: 240x151+87+257... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

2. Shell Programming and Scripting

Printing unique numbers from each file

I have some files named file1, file2, fille3......etc. These files are in a folder f1. The content of files are shown below. I would like to count the unique pairs of third column in each file. some files have no data. It should be printed as zero. Your help would be appreciated. file1 ARG... (1 Reply)
Discussion started by: samra
1 Replies

3. UNIX for Dummies Questions & Answers

printing array elements

Is there a way to print multiple array elements without iterating through the array using bash? Can you do something like... echo ${array}and get all those separate elements from the array? (2 Replies)
Discussion started by: jrymer
2 Replies

4. UNIX for Dummies Questions & Answers

Help with printing sorted expression

Hi All, How can I print the sorted results of the following expression in Perl ?? print "$i\t$h{$i}\n"; I tried print (sort ("$i\t$h{$i}")"\n"); and other variations of the same but failed. Can someone suggest how to solve this problem, as I'm tryin print sorted results of my script, which... (11 Replies)
Discussion started by: pawannoel
11 Replies

5. UNIX for Dummies Questions & Answers

Help required on Printing of Numbers, which are missing in the range

Hi Experts, Need help on printing of numbers, which are missing in the range. Pls find the details below Input 1000000002 1000000007 1234007940 1234007946 Output 1000000003 1000000004 1000000005 1000000006 1234007941 (2 Replies)
Discussion started by: krao
2 Replies

6. Shell Programming and Scripting

Printing the sum of a numbers

Hi I am writing a script that will produce the total of the digits with in the number. Here is the script. -bash# cat Sum_Digits if then echo "You must enter at least two digits" echo "If you enter more than two digits after the base line program this script will print the sum of the... (4 Replies)
Discussion started by: chrs0302
4 Replies

7. Shell Programming and Scripting

Printing the column that begins with certain words/numbers

Hi guys, I have got a file which doesn't have the same number of columns in each line. I would like to print the second column and the one that begins with 33= and has some numbers after '33=' Can you please help me asap? Cheers (7 Replies)
Discussion started by: alexandra_ola
7 Replies

8. Shell Programming and Scripting

Array Printing Inline

Dear friends , The output file of below script Pls#!/bin/sh awk '{ bo = substr($0,13,3) slm = substr($0,150,8) slo = substr($0,175,7) inc = substr($0,97,10)/100 busi = substr($0,83,10) mth = substr($0,39,2) yer = substr($0,35,4) ... (2 Replies)
Discussion started by: vakharia Mahesh
2 Replies

9. UNIX for Dummies Questions & Answers

Printing line numbers

Maybe this question is out there, but I searched and didnt see it. To print my files I use more filename | lpr -Pprinter I would like to print my scripts with line numbers. How do I do this? (2 Replies)
Discussion started by: MizzGail
2 Replies
Login or Register to Ask a Question