Help with sed Syntax

P}l Kvamme kvamme%vax.runit.unit.uninett at NTA-VAX.arpa
Wed Oct 22 22:38:21 AEST 1986


> I'm have been trying (unsuccessfully) to determine what the correct syntax
> would be for sed to substitute a given expression with multiple newlines.
> ....
> For example,I would like to do something like the following:
>
>    s/^ 0/\
>    /
>
>where the backslash is to escape a newline character.

Try this:
     /^ 0/i\            # insert text before all occurences of ^ 0
                        # text to insert - a blank line
     s/^ 0//            # get rid of the ^ 0 on the start of the line

Of course, it only works when the expression to substitute is at column 1.
Beware of quoting shell metacharacters. 
It might be best to place the commands on a file, and use sed -f cmds.

P}l Kvamme
Computer science student
NIT, Trondheim, Norway
ARPA:  kvamme at vax.runit.unit.uninett@tor.arpa
VOICE: + 47 7 593674



More information about the Comp.unix mailing list