Dec 9, 2003 #1 ianicr IS-IT--Management Joined Nov 4, 2003 Messages 230 Location GB Is there a command or script to randomize the lines of a file? Thanks
Dec 9, 2003 1 #2 Ygor Programmer Joined Feb 21, 2003 Messages 623 Location GB One way... awk 'BEGIN {srand} {do x=rand; while(a[x]!="" a[x]=$0} END {for(x in a) print a[x]} ' infile Upvote 0 Downvote
One way... awk 'BEGIN {srand} {do x=rand; while(a[x]!="" a[x]=$0} END {for(x in a) print a[x]} ' infile
Dec 9, 2003 #3 SamBones Programmer Joined Aug 8, 2002 Messages 3,186 Location US Here's a Korn shell version... Code: #!/bin/ksh typeset -RZ6 KEY while read RECORD do KEY=${RANDOM} print "${KEY}:${RECORD}" done < file.orig | sort -n | sed 's/^[0-9]*://1' > file.unsorted ...where [tt]file.orig[/tt] and [tt]file.unsorted[/tt] are the input and output files. Hope this helps. Upvote 0 Downvote
Here's a Korn shell version... Code: #!/bin/ksh typeset -RZ6 KEY while read RECORD do KEY=${RANDOM} print "${KEY}:${RECORD}" done < file.orig | sort -n | sed 's/^[0-9]*://1' > file.unsorted ...where [tt]file.orig[/tt] and [tt]file.unsorted[/tt] are the input and output files. Hope this helps.
Dec 10, 2003 Thread starter #4 ianicr IS-IT--Management Joined Nov 4, 2003 Messages 230 Location GB Thanks for both. Used the awk one and it worked great! Upvote 0 Downvote