gnu@hoptoad.uucp (John Gilmore) (02/22/86)
I was trying to see why my "unshar" shell script didn't work today. It uses sed to cut off the top part of a file and then pipes it to the shell. Here's the line in question: sed "1,/${delim-cut}/d" $x | sh Unfortunately, due to brain damage or lack of foresight, whoever wrote "sed" never considered that you might want a command with two addresses to operate on exactly one line. If the delimiter ("cut" by default) is on the first line, sed deletes that line and then searches the file for another "cut". I got mad and took it out on Laura for a while (she suggested echoing a blank line onto the front of the file before running sed; I thought a text editor ought to be able to do better than that) but I eventually calmed down enough to read the sed manual and figure out a god-awful kludge for doing what the program ought to be doing in the first place -- or at least should have an option to do (to avoid breaking old scripts). Here's my kludge: sed -n -e '/cut/bn' -e 'b' -e ':p' -e 'p' -e ':n' -e 'n' -e 'bp' $x | sh If you don't understand it, don't complain to me; complain to whoever wrote "sed". (Lee E. McMahon wrote the documentation but I'd hate to accuse him unjustly.) I'd suggest an option flag to indicate "two-address commands can match a single line". I don't have access to AT&T sources anymore, though. Anybody have a public domain sed that I can fix? -- John Gilmore {sun,ptsfa,lll-crg,ihnp4}!hoptoad!gnu jgilmore@lll-crg.arpa