Results 1 to 7 of 7
Hi there,
Can someone let me know how to sort the 2 dimensional array below by column 1 then by column 2?
22 55
2222 2230
33 66
44 58
...
- 08-05-2010 #1Just Joined!
- Join Date
- Apr 2009
- Posts
- 12
sorting 2 dimension array
Hi there,
Can someone let me know how to sort the 2 dimensional array below by column 1 then by column 2?
22 55
2222 2230
33 66
44 58
222 240
11 25
22 60
33 45
output:
11 25
22 55
22 60
33 45
33 66
44 58
222 240
2222 2230
Please note that this is a small part in my awk script. the input data is not in file, but it was manipulated in my script.
Could you suggest a code to solve this?
Thanks,
Phoebe
- 08-05-2010 #2Just Joined!
- Join Date
- Apr 2009
- Posts
- 12
nobody happen to this kind of problem? please advice.
- 08-05-2010 #3Linux Newbie
- Join Date
- Sep 2004
- Location
- UK
- Posts
- 160
man sort
Code:cat datafile | sort -t " " -n -k 1,2 or sort -t " " -n -k 1,2 datafile
In a world without walls and fences, who needs Windows and Gates?
- 08-05-2010 #4Just Joined!
- Join Date
- Apr 2009
- Posts
- 12
unfortunately, as I mentioned in the question, my input data is not a file. The input data was manipulated in the script.
I wish to sort the array in the awk script.
Thanks,
- 08-06-2010 #5
then pipe the output of awk to the sort.
- 08-06-2010 #6Just Joined!
- Join Date
- Apr 2009
- Posts
- 12
the two dimension array was generated through a looping for 2000 times. In the end of loop, I would have a table created with first column consists of the array[,1] for each, and second column consist of array[,2] for each.
1 11,22,22,33,33,44,222,2222 25,55,60,45,66,58,240,2230
I can't pipe the output in each loop to the sort, right?
I'm new with awk scripting. Please advice.
- 08-09-2010 #7
but you can pipe the whole output, right?
if you have scriptA, you can pipe the output of it to scriptB by doing:
or doing (within scriptA):Code:scriptA | scriptB
Code:output=""; for i in $(seq 5); do output="${output} something"; done; echo $output | sort


Reply With Quote