sed script to add >'s to quoted text

Tom Christiansen tchrist at convex.COM
Sun Feb 24 04:10:25 AEST 1991


>From the keyboard of rbr at bonnie.ATT.COM (Bob Rager):
:In article <Feb.23.10.31.33.1991.12538 at pilot.njin.net> dblack at pilot.njin.net (David Alan Black) writes:
:>Can someone please explain why the following doesn't work (I'll reproduce
:>the whole session):
:>
:>pilot% cat > quote
:>sed s/^/\>/ -e $1 > $1.quoted
:>^D
:>pilot% chmod a+x quote
:>pilot% quote friend.letter
:>quote: />/: not found
:>pilot% sed: Illegal or missing delimiter: s/
:>
:Your problem is that the shell can see the \> which it takes as a
:literal and redirection. Try this:

No, that's not why it doesn't work.  It's the old shell interpreting ^ as
a pipe.  Quoting the whole thing works.  

    #!/bin/sh
    sed 's/^/>/' -e $1 > $1.quoted

Here's actually more what I use. I like filters better than programs
that operate on fixed filenames.  I also don't see why I should call
the sh if I can avoid doing so (systems without #! are out of luck):

    #!/bin/sed -f
    s/^./> &/

Most mail readers and editors give you a way to this easily.  For example,
I'm an mh-and-vi kind of guy, so I've this binding set up in my .exrc:

" caveat emptor: this line has been run through 'cat -v'
map \r 1G/^-/^[:r!sed -e '1,/^$/d' -e 's/^./> &/' @ ^[/^-/^[j
"	read in @, quoted (for MH replies, who link @ to current file)

I could have done it all in vi, but it ends up faster in sed.

--tom
-- 
"UNIX was not designed to stop you from doing stupid things, because
 that would also stop you from doing clever things." -- Doug Gwyn

 Tom Christiansen                tchrist at convex.com      convex!tchrist



More information about the Comp.unix.shell mailing list