Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Sep 2007 20:52:17 -0700
From:      Gary Kline <kline@tao.thought.org>
To:        Howard Goldstein <hg@queue.to>
Cc:        Gary Kline <kline@tao.thought.org>, freebsd-questions@freebsd.org
Subject:   Re: sed question...
Message-ID:  <20070925035217.GC50519@thought.org>
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 Mon, Sep 24, 2007 at 11:07:20PM -0400, 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.
> > 	Question one, can anybody explain the following syntax?  What do
> > 	"P", "D" "ba" represent, in other words?
> > 
> > 
> >  # 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 ?
> 

	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.
-- 
  Gary Kline  kline@thought.org   www.thought.org  Public Service Unix
      http://jottings.thought.org   http://transfinite.thought.org




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070925035217.GC50519>