Date: Sat, 17 Jan 2004 13:07:06 +1030 From: "Rob" <listone@deathbeforedecaf.net> To: <questions@freebsd.org>, "Brett Glass" <brett@lariat.org> Subject: Re: General UNIX puzzle Message-ID: <01c401c3dca2$cd2766b0$a4b826cb@goo> References: <6.0.0.22.2.20040116192550.05046df8@localhost>
next in thread | previous in thread | raw e-mail | index | archive | help
Brett Glass asked on Saturday January 17, 2004: > 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? > Use the NR variable in nawk(1): nawk 'NR == 25 { next } ; { print }' nawk '{ print } ; NR == 25 { print "string" }'
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?01c401c3dca2$cd2766b0$a4b826cb>