O'Reilly logo

Unix Power Tools, 3rd Edition by Mike Loukides, Tim O'Reilly, Shelley Powers, Jerry Peek

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 34. The sed Stream Editor

sed Sermon^H^H^H^H^H^HSummary

^H^H^H are ASCII backspace characters. Written printably in email and Usenet messages, they’re a tongue-in-cheek way of “erasing” the characters before without actually erasing them. They let you say “I didn’t want you to see that” when you actually do.

sed (stream editor) amazes me. Why? It’s not just that sed can edit data as it streams through a pipe (like all well-behaved Unix filters (Section 1.5) do). sed can test and branch and substitute and hold and exchange data as it streams through, but so can almost any scripting language. Maybe it’s the minimalist in me that loves a tiny program (by today’s standards, at least) with just a few operations — but operations so well-chosen that they make the tool powerful for its size. Sure, sure, Perl probably can do everything that sed can — and do each of those things in twenty different ways. Ah, I’ve got it: when I’m trying to do anything more than a simple substitution on data streaming by, sed’s elegant simplicity almost forces me to strip a problem to its basics, to think of what I really need to do. No functions, no libraries, nothing except beautifully simple functionality.

[As someone who learned Perl regular expressions before I learned sed, I can relate to what Jerry is saying. One of the things I like about the classic Unix toolbox programs like sed is that they really do force you into a sort of Shaker-like elegant simplicity; the best programs, no matter what ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required