i command in sed - only one address?
Geoff Clare
gwc at root.co.uk
Wed May 1 23:51:25 AEST 1991
ceblair at ux1.cso.uiuc.edu (Charles Blair) writes:
| I would like to put a line before ranges in a file. Something like
|
| sed '/A/,/B/i\
| INSERTED LINE' < file1 > file2
|
| but when I try this, I get an error message saying ``only one address.''
jik at athena.mit.edu (Jonathan I. Kamens) writes:
> Because, as sed is pointing out, the 'i' command only takes one address.
>You need to loop through the lines in the region, inserting the text before
>each of them. Something like this:
>/A/{
> :loop
> i\
>INSERTED LINE
> /B/b
> n
> b loop
>}
There's a much simpler way:
sed '/A/,/B/{
i\
INSERTED LINE
}' < file1 > file2
--
Geoff Clare <gwc at root.co.uk> (Dumb American mailers: ...!uunet!root.co.uk!gwc)
UniSoft Limited, London, England. Tel: +44 71 729 3773 Fax: +44 71 729 3273
More information about the Comp.unix.questions
mailing list