by vortico · 11y ago · 0 comments
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 input 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.