How to Shuffle and Sample on the Command-Line
blog.jpalardy.com
How to Shuffle and Sample on the Command-Line
1–10 of 21 posts
Re: How to Shuffle and Sample on the Command-Line
#2 sort -r | head -n100
but obviously this requires the entire file to be shuffled before printing the first 100 lines.Re: How to Shuffle and Sample on the Command-Line
#3Good to know things are still getting better in coreutils!
Re: How to Shuffle and Sample on the Command-Line
#4 man shufRe: How to Shuffle and Sample on the Command-Line
#5Nice! I've been using sort -r | head -n100 but obviously this requires the entire file to be shuffled before printing the first 100 lines.
awk "BEGIN { srand($RANDOM) } { print int(rand() * 1000000), \$0 }" | sort -n | cut -d' ' -f2-
to shuffle an inputRe: How to Shuffle and Sample on the Command-Line
#6Re: How to Shuffle and Sample on the Command-Line
#7How does this handle files that are gigs in size? It looks to me like you load the entire file into memory and pass it along, shuffled.
Re: How to Shuffle and Sample on the Command-Line
#8Nice! I've been using sort -r | head -n100 but obviously this requires the entire file to be shuffled before printing the first 100 lines.
The -R option not being available on OS X, you might do something like awk "BEGIN { srand($RANDOM) } { print int(rand() * 1000000), \$0 }" | sort -n | cut -d' ' -f2- to shuffle an input
Re: How to Shuffle and Sample on the Command-Line
#9Earlier quoted context omitted.
The -R option not being available on OS X, you might do something like awk "BEGIN { srand($RANDOM) } { print int(rand() * 1000000), \$0 }" | sort -n | cut -d' ' -f2- to shuffle an input
http://bost.ocks.org/mike/shuffle/compare.html
awk "{print rand(), $0}" | sort -g | cut -d' ' -f2-
which is shorter allows more than 1,000,000 random values, namely ~52bits in awk's 64bit implementations.Re: How to Shuffle and Sample on the Command-Line
#10man shuf
$ man -k shuffle
gives
pstops (1) - shuffle pages in a PostScript fileI wish I knew about shuf. I've been using sort -R or using Python.