From bodec@sherwood.co.uk Tue Dec 3 22:11:27 1996 Path: fu-berlin.de!news.mathworks.com!EU.net!usenet2.news.uk.psi.net!uknet!usenet1.news.uk.psi.net!uknet!dispatch.news.demon.net!demon!bodecpc.sherwood.co.uk!not-for-mail From: Casper Boden-Cummins Newsgroups: comp.editors,comp.unix.shell Subject: Re: [Q] Script, SED/vi Question.... Date: Mon, 02 Dec 1996 14:42:27 -0800 Lines: 53 Message-ID: <32A35B52.756D@sherwood.co.uk> References: <57r6rd$hu0@alpha.NetUSA.Net> NNTP-Posting-Host: bodecpc.sherwood.co.uk X-NNTP-Posting-Host: bodecpc.sherwood.co.uk X-Mailer: Mozilla 3.0 (Win16; I) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Xref: fu-berlin.de comp.editors:21951 comp.unix.shell:44364 Eli The Bearded wrote: > > (Crossposting and follow-ups modified. This is more of a comp.editors > question. Posted and cc'ed to Don.) > > Icarus Sparry wrote: > >DonQ wrote: > >>I'm a newbie who wants to write a shell script to take a file as a > >>parameter and insert three additional text lines in this file, > >>starting at row #2. > >>Can this be acomplished with SED or "vi +c [commands]"? Any other ways of > >>doing this? This is very easy for sed. For example, create a sed script tmp.sed: #! /bin/sed -f 2i\ 1st inserted line\ 2nd inserted line\ 3rd inserted line `2i' is the important instruction. All text lines following it, up to and including the first line not ending with a blackslash, are inserted *at*, not after, line 2. Don't forget to make it executable: chmod +x tmp.sed Now, create the input file tmp.input: line 1 line 2 line 3 And say: tmp.sed tmp.input and we get... line 1 1st inserted line 2nd inserted line 3rd inserted line line 2 line 3 sed is a useful tool for messing around with text files. For examples and tutorials, see my sed Web site at http://www.wollery.demon.co.uk/. There are also links to other Web sites, sed binaries, and more. Casper Boden-Cummins.