Date: Tue, 25 Sep 2007 09:31:04 +0300 From: Nikos Vassiliadis <nvass@teledomenet.gr> To: freebsd-questions@freebsd.org Cc: Howard Goldstein <hg@queue.to>, Gary Kline <kline@tao.thought.org> Subject: Re: sed question... Message-ID: <200709250931.05367.nvass@teledomenet.gr> In-Reply-To: <46F87B68.6090607@queue.to> References: <20070925013723.GA50027@thought.org> <46F87B68.6090607@queue.to>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200709250931.05367.nvass>