From owner-freebsd-questions@FreeBSD.ORG Fri Jan 16 18:37:40 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 EB4CE16A4CE for ; Fri, 16 Jan 2004 18:37:40 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 429C843D53; Fri, 16 Jan 2004 18:37:39 -0800 (PST) (envelope-from jmz@FreeBSD.org) Received: from freefall.freebsd.org (jmz@localhost [127.0.0.1]) i0H2bcFR049362; Fri, 16 Jan 2004 18:37:38 -0800 (PST) (envelope-from jmz@freefall.freebsd.org) Received: (from jmz@localhost) by freefall.freebsd.org (8.12.10/8.12.10/Submit) id i0H2bcb3049359; Fri, 16 Jan 2004 18:37:38 -0800 (PST) (envelope-from jmz) Date: Fri, 16 Jan 2004 18:37:38 -0800 (PST) Message-Id: <200401170237.i0H2bcb3049359@freefall.freebsd.org> From: Jean-Marc Zucconi To: Brett Glass In-Reply-To: <6.0.0.22.2.20040116192550.05046df8@localhost> References: <6.0.0.22.2.20040116192550.05046df8@localhost> X-Mailer: Emacs 21.3.1 cc: questions@freebsd.org 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:41 -0000 >>>>> Brett Glass writes: > 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? sed -e Nd 2) Insert a specified line in a file after the Nth line, leaving the rest > of the text the same? sed -e 'Na\ line of text' 3) Delete the first line containing a particular string? awk '{if (/string/ && i==0) i++; else print $0}' 4) Insert a specified line after the first line containing a particular > string, leaving the rest of the file the same? You can infer it by yourself after 3) Jean-Marc -- Jean-Marc Zucconi -- PGP Key: finger jmz@FreeBSD.org [KeyID: 400B38E9]