Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!mit-eddie!genrad!decvax!tektronix!reed!kab From: kab@reed.UUCP (Kent Black) Newsgroups: comp.unix.wizards Subject: Re: Sed question Message-ID: <4991@reed.UUCP> Date: Wed, 31-Dec-86 13:37:13 EST Article-I.D.: reed.4991 Posted: Wed Dec 31 13:37:13 1986 Date-Received: Thu, 1-Jan-87 03:52:10 EST References: <107@dcl-csvax.comp.lancs.ac.uk> <140@piaget.UUCP> Reply-To: kab@reed.UUCP (Kent Black) Distribution: world Organization: Reed College, Portland, OR Lines: 41 In article <140@piaget.UUCP> jc@piaget.UUCP (John Cornelius, System Manager) writes: >In article <107@dcl-csvax.comp.lancs.ac.uk> david@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 >> > >/^150/a\ >> >-- >John Cornelius >(...!sdcsvax!piaget!jc) This will append the text after every line beginning with '150'. I cannot find a brilliant, elegant solution (but then, I'm neither brilliant nor elegant), but I found a nice crufty one: (don't even attempt this in csh! ;-) $ sed -n '/^150/ { > = > q > } ' filename will write the number of the first line on which /^150/ occurs. You can try to work out the substitution of one sed as input for another; I settled for: $ line=`sed -n '/^150/ { > ... filename` $ sed ''$line' a\ > new text, remember\ > to escape newlines > ' filename The two single quotes before $line are necessary. Hope someone does better; unless you have an overwhelming need for sed, this is easier in awk. -- kab