Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Get A Random Line From A Text File On The Mac Command Line

I'm working on a little command to display a random quote every time I open a new terminal window. I setup a file with a bunch of quotes. Each one is on its own line.

To pull a random quote/line, I'm using :

bash
sort -R quotes.txt | head -1

### Details

- The [TODO: Code shorthand span ] creates a randomized set of lines from the file - Then [TODO: Code shorthand span ] cuts it down to just the first line. It works great

### Notes :

- Lots of notes on the web say to use ` shuf - n 1 ` , but that's not installed by default on my machine running macOS 12.x Monterey. - The [TODO: Code shorthand span ] and [TODO: Code shorthand span ] commands were available on my machine without having to install anything. That said, it's possible that something else that I installed with homebrew also installed them. Your milage may vary.