On 12-Oct-01 Ronald Wiplinger wrote:
Off Topic, but here are more clever people ;-)
I am lookinig for way to "unsort" a list of numbers!!!
E.g., I have a list of numbers, each in a line, but I don't want them in order, it should randomly!
Any hints how to do that. And yes, it must be this numbers and not new numbers ;-)
If you want a quick one-off one-liner, the following does it nicely:
Suppose your file, with a separate original number in each line,
is called "temp". Then:
cat temp |
awk 'BEGIN{srand()} {$2=$1; $1=rand(); print $0}' |
sort -n |
awk '{print $2}'
will do it. This basically outputs the original lines in
a random order. (In fact, they don't need to be numbers
thnough, as written, the above will fail if they are text
lines with spaces since the default field separator in awk
is the space; however, if needed, this can be worked round
by changing awk's internal FS and OFS variables in the "awk"
invocations).
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding)