From owner-freebsd-questions@FreeBSD.ORG Tue Sep 25 06:34:14 2007 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A9F5816A418 for ; Tue, 25 Sep 2007 06:34:14 +0000 (UTC) (envelope-from nvass@teledomenet.gr) Received: from smtp.teledomenet.gr (smtp.teledomenet.gr [213.142.128.2]) by mx1.freebsd.org (Postfix) with ESMTP id 5376913C455 for ; Tue, 25 Sep 2007 06:34:14 +0000 (UTC) (envelope-from nvass@teledomenet.gr) Received: by smtp.teledomenet.gr (Postfix, from userid 58) id 8B384142105; Tue, 25 Sep 2007 09:34:13 +0300 (EEST) X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on smtp.teledomenet.gr X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.3 Received: from iris (unknown [192.168.1.71]) by smtp.teledomenet.gr (Postfix) with ESMTP id 854D1142107; Tue, 25 Sep 2007 09:34:10 +0300 (EEST) From: Nikos Vassiliadis To: freebsd-questions@freebsd.org Date: Tue, 25 Sep 2007 09:31:04 +0300 User-Agent: KMail/1.9.1 References: <20070925013723.GA50027@thought.org> <46F87B68.6090607@queue.to> In-Reply-To: <46F87B68.6090607@queue.to> X-NCC-RegID: gr.telehouse MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200709250931.05367.nvass@teledomenet.gr> Cc: Howard Goldstein , Gary Kline Subject: Re: sed question... X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Sep 2007 06:34:14 -0000 On Tuesday 25 September 2007 06:07, Howard Goldstein wrote: > Gary Kline wrote: > > My earlier post about deleting the first N lines was answered by > > this one-liner site {below}. I wasn't including any > > redirection; doing so finally resolved the problem. Now I need > > to delete every line from the 19th or so to the last line. sed -e 18q that is, quit after processing line 18. > > Question one, can anybody explain the following syntax? What do > > "P", "D" "ba" represent, in other words? The manual page explains sed in a very good way. For sure, better than I could describe it here. You'd better read it. > > > > > > # delete the last 10 lines of a file > > sed -e :a -e '$d;N;2,10ba' -e 'P;D' # method 1 > > sed -n -e :a -e '1,10!{P;N;D;};N;ba' # method 2 > > > > > > Question two, can sed do its thing inline? Yes. -i extension Edit files in-place, saving backups with the specified extension. If a zero-length extension is given, no backup will be saved. It is not recommended to give a zero-length extension when in-place editing files, as you risk corruption or partial content in situ- ations where disk space is exhausted, etc. > > Wouldn't it be easier to use head -n 18 ? No, it's the same. Some sed operation are trivial to read/write, others aren't. HTH Nikos