Given inputfile
Cherries:20:100:300
Beans:12:400:500
Tomatoes:32:445:234
Potatoes:24:400:200
Kiwis:23:230:435
I have an awk script, named testscript.script:
BEGIN{ FS = ":" 
print "------------------------"
}
if($3 + $4 > 500) {print $1, $2}
END{
print "------------------------" 
}
The output of this script when invoked with awk -f testscript.script inputfile is as follows: 
------------------------
Beans 12
Tomatoes 32
Potatoes 24
Kiwis 23
------------------------
I want to sort this list alphabetically (by name), then store it to a variable so that this list is printable in the end block of the awk script.
I.e. the code should look something like this.
BEGIN{ FS = ":" 
print "------------------------"
}
*if($3 + $4 > 500) {print $1, $2 | "sort" = variable}
END{
print "------------------------" 
print variable
}
And the print variable command would yield 
------------
------------
Beans 12
Kiwis 23
Potatoes 24
Tomatoes 32
With the sorted list of items as the variable, and printing it in the END block after the dotted line.
What is the best way to do this?



asortifunction?sortcommand can't terminate until it receives an end-of-file, and you nevercloseit, this seems a bit silly. Why not just add a shell wrapper script to pipe the output of the Awk script throughsort?------lines and not before. Did I get that correctly that that's what you want?