Skip to content

Instantly share code, notes, and snippets.

@judotens
Last active December 29, 2015 01:49
Show Gist options
  • Save judotens/7595989 to your computer and use it in GitHub Desktop.
Save judotens/7595989 to your computer and use it in GitHub Desktop.
Randomize the input lines using bash
#!/bin/bash
# randomize the input lines
# cat artikel.txt | ./acak.sh
awk 'BEGIN{srand() }
{ lines[++d]=$0 }
END{
while (1){
if (e==d) {break}
RANDOM = int(1 + rand() * d)
if ( RANDOM in lines ){
print lines[RANDOM]
delete lines[RANDOM]
++e
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment