I am new to Mac OS X but come from the FreeBSD world so I'm having fun finding out what is here and what isn't. I just realized that one of my favorite tools, 'jot', is here and I wanted to point this out to people. jot allows you to print sequential and random data. More specifically, it allows you to do some really cool things in the shell. Let me give you an example.
I am a big fan of the online music trading organization Etree. There are well-established ways of organizing and naming the concerts that are traded. Occasionally I'll come across a downloaded show that doesn't follow the scheme. Say there are several songs from a Phish show named something like '2001-05-26-phish-d1t1.shn'. The correct format should be 'ph01-05-26d1t1.shn' It would be a real pain in the ass to rename them, right? Well, with jot the answer is a resounding "NO!"
Read the rest of this article for a great primer on using 'jot'...
First, let's look at some basics. Open up a terminal shell and type: "jot 3 1" and hit enter. What you'll see is this:
1What those basic options did was to generate a series of numbers (3) beginning at 1. Try something 'jot 5 2' or 'jot 10 20'. You may wonder what is so special about that. I'm going to take a monstrous leap here and jump right into some shell programming (if you aren't familiar with it, I encourage you to find some online documentations, buy a book or something). Please also note that the syntax used here is of the Bourne shell variety. If you don't have 'bash' installed, when you open up a terminal window, type 'sh' and then enter to run a Bourne shell. With modified syntax, these same examples could run under csh/tcsh.
2
3
for i in `jot 10 1`; do echo $i; doneIt looks basically like the normal jot output. But now try:
for i in `jot 10 2`; do echo "I wish I had $i dollars"; doneNotice how easy it was to integrate text and a sequence of numbers? Perhaps now you are beginning to see the power of jot. Let's look at some other features before tackling our renaming problem.
jot -b Input 10 1 > inputfileIf you type 'cat inputfile' you'll see that the word 'Input' has been generated ten times. This is a useful way to generate files that need to be of a certain size or to test boundary conditions, buffering, etc.
jot -r 10 1 > randomdatanow type 'cat randomdata' to see the results.
jot -w "file%d" 10 1You should see:
file1If you want to specify leading zeros and two digits you would say:
file2
file3
file4
.
.
file10
jot -w "file%02d" 10 1(n.b. leave off the zero for a space-padded number that takes up two digits).
for i in `jot 10 1`; do mv 2001-05-26-phish-d1t$i.shn ph01-05-26d1t$i.shn; doneWhat would have been cumbersome to do manually becomes a snap with this great tool. If we then want to unshorten only the first disc's files and encode the resulting .wav files as .mp3s, we could say:
for i in `jot -w "ph01-05-26d1t%d"; do shorten -x $i.shn $i.wav; rm $i.shn; bladenc -del $i.wav; doneIn one swell foop, you've combined several powerful commands into a sequential and specific flow that takes only seconds to type.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20011117235743849