Created
February 12, 2014 13:10
-
-
Save unhammer/8955298 to your computer and use it in GitHub Desktop.
For every PERIOD lines, output a random line from that set of lines
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 | |
set -e -u | |
if [[ $# -ne 1 ]];then | |
echo "Usage: $0 PERIOD" | |
echo "For every PERIOD lines, output a random line from that set of lines" | |
echo "E.g. printf '%s\n' {1..30} | $0 7" | |
echo "might output 5, 12, 19, 23 and 30." | |
exit 1 | |
fi | |
gawk -vseed=$RANDOM -vperiod=$1 ' | |
BEGIN{ | |
srand(seed) | |
} | |
NR%period == 1 { | |
mod=int(period*rand()) | |
} | |
NR%period == mod { | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment