Last active
December 29, 2015 01:49
-
-
Save judotens/7595989 to your computer and use it in GitHub Desktop.
Randomize the input lines using bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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