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
09-22-2010, 03:04 PM
Maciej Grela
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
09-22-2010, 03:06 PM
Remy Blank
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
09-22-2010, 03:11 PM
Florian CROUZAT
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. /
09-22-2010, 03:43 PM
Paul Hartman
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
09-22-2010, 03:47 PM
Al
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
09-22-2010, 03:55 PM
Alan McKinnon
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
09-22-2010, 10:12 PM
David Relson
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