Re: Random list of filenames



On Mon, 30 Jul 2007 02:24:16 +1200, Rob S wrote:

I have a directory with >500 files. I want to divide the 500 odd files
into 4 groups, each group containing a random assortment of filenames.
I've tried using awk with rand() and srand()until my head was ready to
explode. I'm obviously getting the syntax wrong somewhere, but seeing as
how I know very little about awk, it's not surprising. I've never
professed to calling myself a coder or programmer and I never will. I
just can't seem to wrap my head around scripting.

You already have several nice solutions, though, just
in case the main requirement was equality prior to
'randomness' this could be a simple idea of algorithm:

'{v[$0]=NR%4} END{ for(f in v){print f v[f] } }'

Sample here, in the form of a script preproc:

$ seq 17 | awk '{v[$0]=NR%4} END{ for(f in v){print "mv " f " " f "_in_set_" v[f] } }'
mv 17 17_in_set_1
mv 4 4_in_set_0
mv 5 5_in_set_1
mv 6 6_in_set_2
mv 7 7_in_set_3
mv 8 8_in_set_0
mv 9 9_in_set_1
mv 10 10_in_set_2
mv 11 11_in_set_3
mv 12 12_in_set_0
mv 13 13_in_set_1
mv 14 14_in_set_2
mv 1 1_in_set_1
mv 15 15_in_set_3
mv 2 2_in_set_2
mv 16 16_in_set_0
mv 3 3_in_set_3
.