Subject: learning and using sed (was about truncate(1))
To: None <>
From: Greg A. Woods <>
List: tech-userlevel
Date: 07/21/2000 22:48:48
[ On Friday, July 21, 2000 at 18:49:31 (-0400), Andrew Brown wrote: ]
> Subject: Re: Suggestion: inclusion of the truncate(1) utility into the tre e
> i've got that.  it has a chapter or two on sed and then spends the
> rest of its time on awk.  it doesn't really tell me much at all.  now
> if there was a book that spent as much time on sed, or something like
> the awk book (by aho, weinberger, and kernighan), that would be good.
> but there ain't.

Well the first thing you need to learn in order to use sed is all there
is to know about ed.

I didn't think I had the O'Reilly "sed & awk" book, but the sed section
is reprinted in chapter 6 of the "Handbook of Programming Langugages
Volume III: Little Languages and Tools", edited by Peter Salus
(published by Macmillan).

That chapter is quite a good tutorial, and does cover all the basics
(except for the the real nitty gritty on regular expressions), but it
doesn't get into some of the really fancy stuff you can do with the hold
space.  I don't see any mention of the "branch to label" (goto!) feature
in there either.

Lee McMahon's original 1978 paper on sed from the "Unix Programmer's
Manual Volume 2, 7th Edition", and especially the version revised by
L. Cherry and printed in the "Unix Research System Papers, Tenth Edition
Volume II", is a bit better than the manual page because it does include
some additional discussion and a few examples.  You can find at least
the first version online at

BTW, until 'less -s' came along this was my favourite and most-used sed
example (perhaps after using "sed 10q" to replace head, that is):

	sed '/./,/^$/!d'

This compresses multiple blank lines into one.

I wish I could say I devised it on my own, but I didn't -- it's origin
though is now likely lost in the mists of time.  Not even the oldest
SCCS file I can find for my ~/.kshrc (1993/11/17) talks about the
addition of the alias that helps me remember that little trick.  It
probably came from Usenet, but I can't remember....

							Greg A. Woods

+1 416 218-0098      VE3TCP      <>      <robohack!woods>
Planix, Inc. <>; Secrets of the Weird <>