From Slashdot, I’ve learned about a new book coming out all about mastering the cat command in Unix and Unix-like systems. This seems as fun as the tac bash shell command (well, I have on at least one or two occasions used tac before, for some strange reason or another). For the Unix uninitiated, cat is a command that simply prints a file on screen. For example, if you have a file called, someinterestingfile.txt, you would type “cat someinterestingfile.txt” to see the whole thing flash by. If it is too big, you could type “cat someinterestingfile.txt | more” or more simply, “more –or less– someinterestingfile.txt”. So why does cat need its own book? From the cat link:
O’Reilly Net: Isn’t mastering cat supposed to be quite easy? Does it really necessitates its own book?
Shlomi Fish: Hell no! Mastering cat is not easy at all. In fact, mastering cat is almost as difficult as herding cats.
For example, one case where I found that people truly underestimate the power of cat is in the prefixing a line example. You can do that with:
echo “This would be the first line” | cat – myfile.txt > myfile.txt.new
mv -f myfile.txt.new myfile.txt
But people do not realize that and instead opted to use sed, awk, or even perl (!). It can be taken further, of course. If the prefix is already in its own file, you can simply use cat prefix.txt myfile.txt
Of course, if you want to append the same text to both the start and the end of a file, you can’t do that with cat – myfile.txt -. It simply doesn’t work that way. So, I end up explaining a lot about UNIX pipeline concepts in the book.
I’m looking forward to his next book on echo.
On a completely unrelated note, Happy April 1st everybody!