bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "line" utility


From: Bob Proulx
Subject: Re: "line" utility
Date: Mon, 11 Jul 2005 23:09:11 -0600
User-agent: Mutt/1.5.9i

Michael Tewner wrote:
> Is there a reason that there isn't a tool that prints one or more lines 
> from within a file?
> 
> For years, everyone has been doing this with ` head | tail `
> 
> ...or is there a program that does this already?

Brian Dessent wrote:
> seq 1 50 | sed -n 3,25p
> sed 1 50 | sed -n 11,+10p   # gnu sed only

And fancy stuff is available too.

  seq 1 50 | sed -n '3,4p;10p;12,14p'

Or use awk as it is one of the standard utilities as well.  (NR is the
number of records (lines) seen so far.)

  seq 1 50 | awk '5 <= NR && NR <= 9'

But you can really get fancy with it such as printing the odd lines
between 5 and 30.

  seq 1 50 | awk '5 <= NR && NR < 30 { if (NR % 2) print; }'

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]