FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo User

 
 
LinkBack Thread Tools
 
Old 09-22-2010, 02:53 PM
Al
 
Default Not head, not tail, maybe belly

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
 
Old 09-22-2010, 03:04 PM
Maciej Grela
 
Default Not head, not tail, maybe belly

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
 
Old 09-22-2010, 03:06 PM
Remy Blank
 
Default Not head, not tail, maybe belly

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
 
Old 09-22-2010, 03:11 PM
Florian CROUZAT
 
Default Not head, not tail, maybe belly

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. /
 
Old 09-22-2010, 03:43 PM
Paul Hartman
 
Default Not head, not tail, maybe belly

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
 
Old 09-22-2010, 03:47 PM
Al
 
Default Not head, not tail, maybe belly

>> 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
 
Old 09-22-2010, 03:55 PM
Alan McKinnon
 
Default Not head, not tail, maybe belly

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
 
Old 09-22-2010, 10:12 PM
David Relson
 
Default Not head, not tail, maybe belly

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
 

Thread Tools




All times are GMT. The time now is 03:43 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org