From owner-freebsd-questions@FreeBSD.ORG Tue Sep 25 16:25:10 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 77DC116A417 for ; Tue, 25 Sep 2007 16:25:10 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id BF61113C45B for ; Tue, 25 Sep 2007 16:25:09 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (vader.bytemobile.ondsl.gr [83.235.244.135]) (authenticated bits=128) by igloo.linux.gr (8.14.1/8.14.1/Debian-9) with ESMTP id l8PGOhUB013871 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 25 Sep 2007 19:24:59 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.1/8.14.1) with ESMTP id l8PGOR7s013597; Tue, 25 Sep 2007 19:24:42 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.1/8.14.1/Submit) id l8PGOPdf013596; Tue, 25 Sep 2007 19:24:25 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Tue, 25 Sep 2007 19:24:25 +0300 From: Giorgos Keramidas To: Gary Kline Message-ID: <20070925162424.GA13463@kobe.laptop> References: <20070925013723.GA50027@thought.org> <46F87B68.6090607@queue.to> <20070925035217.GC50519@thought.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070925035217.GC50519@thought.org> X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.97, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.43, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: Howard Goldstein , freebsd-questions@freebsd.org 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 16:25:10 -0000 On 2007-09-24 20:52, Gary Kline wrote: >On Mon, Sep 24, 2007 at 11:07:20PM -0400, Howard Goldstein wrote: >>> # 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? >> >> Wouldn't it be easier to use head -n 18 ? If you _know_ that the file has 28 lines, yes. If you don't, then itmay be tricky to 'guess' that -n 18 is the right option. > No, because most of these files are between 40 and 50 lines. I only > care about the first 30 or 40; everything below has to be deleted. By > hand, using vi, I might type :31,$d that fixes that one file. Of > course, I could simply edit in "19" for "10" above. It would be more > savvy to understand the sed syntax. You don't need to manually edit files with vi(1) if all you want to do is type ``:31,$d:wq'' ... sed -i '' -e '31,$d' file.txt