Herding Cats

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!


Tags: , ,

2 Responses to “Herding Cats”

  1. How should I go about converting my cats to a raw food diet? | List of Low Carbohydrate Foods Says:

    […] Herding Cats « The Liquid Thinker […]

  2. Dog herding kittens | K9 Games Says:

    […] PledgeRelated Blogs on HerdingFive online community tools (and what to use them for) « ISEAL …Herding Cats « The Liquid ThinkerHerding Cats II: Attack of the Hairball | Books of MeeEpisode 40: Shawn Wildermuth on Silverlight 3 […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: