Sed question

Anders Weinstein aweinste at Diamond.BBN.COM
Fri Dec 19 07:06:09 AEST 1986


In article <107 at dcl-csvax.comp.lancs.ac.uk> david at comp.lancs.ac.uk (David T. Coffield) writes:
>In "sed" how can does one form a command to do the following:
>
>Take file A, find the first line beginning with a 150,
>append a line of text at that point and then write out
>file A (all of it) with the newly inserted line.

If the pattern /^150/ is only going to occur once in the input, then it's
easy:

    /^150/a\
    line-of-text-to-append-here

Otherwise, you could try using two loops in the script as follows:

    :loop1
    /^150/{
    a\
    line-of-text-to-append-here
    b loop2
    }
    n
    b loop1
    :loop2
    n
    b loop2

--
Anders Weinstein	<aweinste at DIAMOND.BBN.COM>



More information about the Comp.unix.wizards mailing list