Sunday, August 06, 2017
Small Victories
Sometimes finding the right command in Linux shell can be an uphill struggle.
I seem to spend hours at a time looking for a simple and elegant solution to a problem only to find long winded articles on how to achieve the result I'm looking for. Today was one such day.
All I wanted to do was re-arrange a list in a random order. There were plenty of articles on how to choose a single item on the list randomly but nothing about my particular problem.
Then I came across the shuf command. There were a few solutions that were close but not quite what I wanted. This is where man pages come into their own. The man page for shuf is short and sweet and all the options I needed are right there on the page. After a little trial and error I wrote a short and elegant command (see above) that does exactly what I want.
How does it work?
I make a list with each item on a different line in a text file and the command writes another text file with the same list but in a random order. Simple.
One more Linux victory under my belt.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment