bash Pro-TipTM: Select a Random Line
I can’t count the number of times I’ve wanted a simple random selection from a file. I always get confused by trips down $RANDOM and perl-isms, but no more! I present to you:
... | sort -R | head -1
sort -R — sort by random hash of keys.
Developers of sort, you are mad geniuses for hiding “put things in correct order” and “put things in totally incorrect order” in the same place.
16:09 CST | category / entries
permanent link | comments?