sed question

Steven List itkin at luke.UUCP
Wed Oct 2 05:20:35 AEST 1985


In article <1492 at uwmacc.UUCP> jwp at uwmacc.UUCP (Jeffrey W Percival) writes:
>sed(1) allows you to give the script on the command line like this:
>
>	sed -e 'script' file1 > file2
>
>Some of the sed commands, like a\ and i\ seem to need additional
>lines of input.  I know that if I use the "-f sedfile" option I
>can stash the commands in a file, but is there a way I can use
>"append" and "insert" with the -e option?

Yep.  First, use the Bourne shell. Then, type the command exactly as
it would appear in a sed command file.  The example I tried (so I
wouldn't sound like an idiot when I posted this) is:

% sh
$ echo hello | sed -e 'a\
there\
chum'
hello
there
chum

Pretty simple, huh?  Apparently the single quote escapes the backslash
escape so that sed sees it just as typed.  This same kind of thing holds
true for commands like echo:

$ echo "This is a multi-line
output example from echo"
This is a multi-line
output example from echo

This lets you create whole screenfulls of output with one invocation of
the echo command.
-- 
***
*  Steven List @ Benetics Corporation, Mt. View, CA
*  Just part of the stock at "Uncle Bene's Farm"
*  {cdp,greipa,idi,oliveb,sun,tolerant}!bene!luke!itkin
***



More information about the Comp.unix mailing list