Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!mcsun!ukc!pyrltd!root44!gwc From: gwc@root.co.uk (Geoff Clare) Newsgroups: comp.unix.questions Subject: Re: i command in sed - only one address? Message-ID: <2698@root44.co.uk> Date: 1 May 91 13:51:25 GMT References: <1991Apr29.131718.26624@ux1.cso.uiuc.edu> <1991Apr29.201315.7790@athena.mit.edu> Organization: UniSoft Ltd., London, England Lines: 33 ceblair@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@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 (Dumb American mailers: ...!uunet!root.co.uk!gwc) UniSoft Limited, London, England. Tel: +44 71 729 3773 Fax: +44 71 729 3273