dblack@pilot.njin.net (David Alan Black) (02/23/91)
I am trying to devise a simple shell script to add ">" to the beginning of every line of a text file containing an article or letter which I wish to quote in my response. 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/ It then sits there NOT giving me the % prompt, until I hit return (if that matters). Used interactively, the sed formula above has worked. I must be doing some- thing wrong in converting it to script form. Please advise - Thanks in advance, David Black dblack@pilot.njin.net "I was....now!" Mrs. Emma Peel
rbr@bonnie.ATT.COM (4197,ATTT) (02/24/91)
In article <Feb.23.10.31.33.1991.12538@pilot.njin.net> dblack@pilot.njin.net (David Alan Black) writes: >I am trying to devise a simple shell script to add ">" to the beginning of >every line of a text file containing an article or letter which I wish to >quote in my response. > >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/ > > Mrs. Emma Peel Your problem is that the shell can see the \> which it takes as a literal and redirection. Try this: cat >quote <<EOD sed -e "s/^/\\>/" $1 >$1.quoted EOD quote letter Note "-e" is not a switch, it is a non-positional command line parameter. An edit script must follow it. Hope this helps. Bob Rager Ain't no place like ${HOME}.
dmk@pilot.njin.net (David M. Katinsky) (02/24/91)
I think you want your sh(1) script to contain the following: #!/bin/sh sed -e 's/^/\>/' $1 > $1.quoted -- dmk David M. Katinsky dmk@pilot.njin.net, dmk@njin.BITNET, {njin, rutgers}!dmk
Dan_Jacobson@ATT.COM (02/24/91)
>>>>> On 23 Feb 91 15:31:35 GMT, dblack@pilot.njin.net (David Alan Black) said:
David> I am trying to devise a simple shell script to add ">" to the
David> beginning of every line of a text file containing an article or
David> letter which I wish to quote in my response.
You see, you are going about this all wrong. Your mail reader or news
reader software should have the ability to put those ">"'s in (and
take them out on lengthy quoted material that you are reading) for
you.
Some users, like my bad self, prefer even better than those wimpy
">"'s, e.g., someting dynamically chosen, like "David>" here, produced
by GNU Emacs + GNUS + SuperCite, available in your grocers' freezer
(actually, read the gnu.* groups for availability).
--
Dan_Jacobson@ATT.COM Naperville IL USA +1 708-979-6364
tchrist@convex.COM (Tom Christiansen) (02/24/91)
From the keyboard of rbr@bonnie.ATT.COM (Bob Rager):
:In article <Feb.23.10.31.33.1991.12538@pilot.njin.net> dblack@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@convex.com convex!tchrist
peter@ficc.ferranti.com (Peter da Silva) (02/27/91)
In article <Feb.23.10.31.33.1991.12538@pilot.njin.net> dblack@pilot.njin.net (David Alan Black) writes: > pilot% cat > quote > sed s/^/\>/ -e $1 > $1.quoted > ^D It's a different kind of quoting altogether. The bourne shell considers ^ as an alias for | so you need to quote the first argument to sed: sed 's/^/>/' $1 > $1.quoted I would recommend quoting commands and regular expressions regardless. (in addition, the "-e" option means the following argument is a command: leave it out or put it before the command) -- Peter da Silva. `-_-' peter@ferranti.com +1 713 274 5180. 'U` "Have you hugged your wolf today?"