public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] Not head, not tail, maybe belly
@ 2010-09-22 14:53 Al
  2010-09-22 15:04 ` Maciej Grela
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Al @ 2010-09-22 14:53 UTC (permalink / raw
  To: gentoo-user

Hi,

I am looking for a program similar to head or tail. It should display
a given range of lines or take a line and a context number like grep.

Any suggestions? Thanks in advance.

Al



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gentoo-user] Not head, not tail, maybe belly
  2010-09-22 14:53 [gentoo-user] Not head, not tail, maybe belly Al
@ 2010-09-22 15:04 ` Maciej Grela
  2010-09-22 15:11   ` Florian CROUZAT
  2010-09-22 22:12   ` David Relson
  2010-09-22 15:06 ` [gentoo-user] " Remy Blank
  2010-09-22 15:43 ` [gentoo-user] " Paul Hartman
  2 siblings, 2 replies; 8+ messages in thread
From: Maciej Grela @ 2010-09-22 15:04 UTC (permalink / raw
  To: gentoo-user

2010/9/22 Al <oss.elmar@googlemail.com>:
> Hi,
>
> I am looking for a program similar to head or tail. It should display
> a given range of lines or take a line and a context number like grep.
>
> Any suggestions? Thanks in advance.
>

grela@pazuzu ~ $ cat /etc/passwd | sed -n -e '4,10 p'
adm:x:3:4:adm:/var/adm:/bin/false
lp:x:4:7:lp:/var/spool/lpd:/bin/false
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/bin/false
news:x:9:13:news:/usr/lib/news:/bin/false

Br,
Maciej Grela



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [gentoo-user] Re: Not head, not tail, maybe belly
  2010-09-22 14:53 [gentoo-user] Not head, not tail, maybe belly Al
  2010-09-22 15:04 ` Maciej Grela
@ 2010-09-22 15:06 ` Remy Blank
  2010-09-22 15:43 ` [gentoo-user] " Paul Hartman
  2 siblings, 0 replies; 8+ messages in thread
From: Remy Blank @ 2010-09-22 15:06 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 278 bytes --]

Al wrote:
> I am looking for a program similar to head or tail. It should display
> a given range of lines or take a line and a context number like grep.

How about combining both? Show 10 lines starting with line 20:

  tail -n +20 <myfile.txt | head -n 10

-- Remy


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 187 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gentoo-user] Not head, not tail, maybe belly
  2010-09-22 15:04 ` Maciej Grela
@ 2010-09-22 15:11   ` Florian CROUZAT
  2010-09-22 15:47     ` Al
  2010-09-22 22:12   ` David Relson
  1 sibling, 1 reply; 8+ messages in thread
From: Florian CROUZAT @ 2010-09-22 15:11 UTC (permalink / raw
  To: gentoo-user


On 22 sept. 2010, at 17:04, Maciej Grela wrote:

> 2010/9/22 Al <oss.elmar@googlemail.com>:
>> Hi,
>> 
>> I am looking for a program similar to head or tail. It should display
>> a given range of lines or take a line and a context number like grep.
>> 
>> Any suggestions? Thanks in advance.
>> 
> 
> grela@pazuzu ~ $ cat /etc/passwd | sed -n -e '4,10 p'


Best solution so far, but useless use of cat, and the subshell overhead of the pipe.

-----
Florian.
/ For security reasons, all text in this mail 
  is double-rot13 encrypted. /




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gentoo-user] Not head, not tail, maybe belly
  2010-09-22 14:53 [gentoo-user] Not head, not tail, maybe belly Al
  2010-09-22 15:04 ` Maciej Grela
  2010-09-22 15:06 ` [gentoo-user] " Remy Blank
@ 2010-09-22 15:43 ` Paul Hartman
  2 siblings, 0 replies; 8+ messages in thread
From: Paul Hartman @ 2010-09-22 15:43 UTC (permalink / raw
  To: gentoo-user

On Wed, Sep 22, 2010 at 9:53 AM, Al <oss.elmar@googlemail.com> wrote:
> Hi,
>
> I am looking for a program similar to head or tail. It should display
> a given range of lines or take a line and a context number like grep.
>
> Any suggestions? Thanks in advance.

sed -n 5,8p filename

where 5 is first line in the range and 8 is the last line.

If you want to view multiple ranges use the same X,Yp syntax but
preceed each with -e. For example

sed -n -e 5,8p -e 12,17p filename



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gentoo-user] Not head, not tail, maybe belly
  2010-09-22 15:11   ` Florian CROUZAT
@ 2010-09-22 15:47     ` Al
  2010-09-22 15:55       ` Alan McKinnon
  0 siblings, 1 reply; 8+ messages in thread
From: Al @ 2010-09-22 15:47 UTC (permalink / raw
  To: gentoo-user

>> grela@pazuzu ~ $ cat /etc/passwd | sed -n -e '4,10 p'
>
>
> Best solution so far, but useless use of cat, and the subshell overhead of the pipe.
>

Thank you. Nice solutions and they reveal that there is no "belly"
like program in coreutils.

I find it interesting, that the two bordercases are considered while
the general approach (range), that would cover all, is missing. Is
that rather for performance or for historical reasons?

Al



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gentoo-user] Not head, not tail, maybe belly
  2010-09-22 15:47     ` Al
@ 2010-09-22 15:55       ` Alan McKinnon
  0 siblings, 0 replies; 8+ messages in thread
From: Alan McKinnon @ 2010-09-22 15:55 UTC (permalink / raw
  To: gentoo-user

Apparently, though unproven, at 17:47 on Wednesday 22 September 2010, Al did 
opine thusly:

> >> grela@pazuzu ~ $ cat /etc/passwd | sed -n -e '4,10 p'
> > 
> > Best solution so far, but useless use of cat, and the subshell overhead
> > of the pipe.
> 
> Thank you. Nice solutions and they reveal that there is no "belly"
> like program in coreutils.
> 
> I find it interesting, that the two bordercases are considered while
> the general approach (range), that would cover all, is missing. Is
> that rather for performance or for historical reasons?
> 
> Al


Neither.

It's because one frequently wants to see the start or end of a file and much 
less seldom something in the middle. When that is what you want, there are all 
manner of other tools to find the bit you want, then display surrounding text.

grep -{ABC} is the usual tool for that


-- 
alan dot mckinnon at gmail dot com



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [gentoo-user] Not head, not tail, maybe belly
  2010-09-22 15:04 ` Maciej Grela
  2010-09-22 15:11   ` Florian CROUZAT
@ 2010-09-22 22:12   ` David Relson
  1 sibling, 0 replies; 8+ messages in thread
From: David Relson @ 2010-09-22 22:12 UTC (permalink / raw
  To: gentoo-user

Or, as a script ...

--- begin bin/belly ---
RANGE=$1
shift
sed -n ${RANGE}p $*
--- end --


On Wed, 22 Sep 2010 17:04:43 +0200
Maciej Grela wrote:

> 2010/9/22 Al <oss.elmar@googlemail.com>:
> > Hi,
> >
> > I am looking for a program similar to head or tail. It should
> > display a given range of lines or take a line and a context number
> > like grep.
> >
> > Any suggestions? Thanks in advance.
> >
> 
> grela@pazuzu ~ $ cat /etc/passwd | sed -n -e '4,10 p'
> adm:x:3:4:adm:/var/adm:/bin/false
> lp:x:4:7:lp:/var/spool/lpd:/bin/false
> sync:x:5:0:sync:/sbin:/bin/sync
> shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
> halt:x:7:0:halt:/sbin:/sbin/halt
> mail:x:8:12:mail:/var/spool/mail:/bin/false
> news:x:9:13:news:/usr/lib/news:/bin/false
> 
> Br,
> Maciej Grela



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-09-22 22:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-22 14:53 [gentoo-user] Not head, not tail, maybe belly Al
2010-09-22 15:04 ` Maciej Grela
2010-09-22 15:11   ` Florian CROUZAT
2010-09-22 15:47     ` Al
2010-09-22 15:55       ` Alan McKinnon
2010-09-22 22:12   ` David Relson
2010-09-22 15:06 ` [gentoo-user] " Remy Blank
2010-09-22 15:43 ` [gentoo-user] " Paul Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox