From owner-freebsd-questions@FreeBSD.ORG Fri Jan 16 18:37:11 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5359416A4CE for ; Fri, 16 Jan 2004 18:37:11 -0800 (PST) Received: from zim.0x7e.net (zim.0x7e.net [203.38.184.132]) by mx1.FreeBSD.org (Postfix) with ESMTP id 22BC343D1F for ; Fri, 16 Jan 2004 18:37:10 -0800 (PST) (envelope-from listone@deathbeforedecaf.net) Received: from goo.0x7e.net ([203.38.184.164] helo=goo) by zim.0x7e.net with smtp (Exim 3.36 #1) id 1AhgKi-0001Bb-00; Sat, 17 Jan 2004 13:07:08 +1030 Message-ID: <01c401c3dca2$cd2766b0$a4b826cb@goo> From: "Rob" To: , "Brett Glass" References: <6.0.0.22.2.20040116192550.05046df8@localhost> Date: Sat, 17 Jan 2004 13:07:06 +1030 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Subject: Re: General UNIX puzzle X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Jan 2004 02:37:11 -0000 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" }'