Date: Fri, 16 Jan 2004 20:48:41 -0800 From: Bill Campbell <freebsd@celestial.com> To: questions@freebsd.org Subject: Re: General UNIX puzzle Message-ID: <20040117044841.GA28385@alexis.mi.celestial.com> In-Reply-To: <6.0.0.22.2.20040116192550.05046df8@localhost> References: <6.0.0.22.2.20040116192550.05046df8@localhost>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Jan 16, 2004, Brett Glass wrote: >I was asked a good question today about how to do some simple tasks using >standard UNIX tools, and am curious what answers people on the list might >come up with. > >What are the simplest, most efficient ways to: > >1) Delete the Nth line from a text file? >2) Insert a specified line in a file after the Nth line, leaving the rest >of the text the same? >3) Delete the first line containing a particular string? >4) Insert a specified line after the first line containing a particular >string, leaving the rest of the file the same? You want to do these things with the file in-place? The old fashioned way to do this is to ed or ex as an in-place upate. # first example (from memory, I would probably have to try these # to be sure they work. ed - << DONE 3d w q DONE # second ed - <<DONE 3a line to be inserted
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040117044841.GA28385>
