Randomize a file lines with AWK
The goal here is simple:- I have a file (music playlist, user list,...)
- I want to disorder it, just like I woul beat the cards
If the file is not too big:
awk < fichier '{a[n++]=$0}
END{for(srand();n--;a[i]=b)
{b=a[n];a[n]=a[i=int(rand()*NR)]};
while(++n<NR)print a[n]}'
Otherwise:
awk < fichier 'BEGIN{srand()}{print rand(),$0}' | sort -k1,1 | cut -d -f2-
I write it down here just for the archives