Thursday, April 12, 2018

Two random words under MacOS

As MacOS doesn't have sort -R, if you want to randomize a list, it gets a bit more complicated.
In order to generate two random words, I'm currently using:
cat /usr/share/dict/words | awk 'BEGIN{srand();}{print rand()"\t"$0}' \
| sort -k1 -n | cut -f2- | awk 'NR <= 2 { print $1 }'

No comments:

Post a Comment