From: Stachu 'Dozzie' K. on
On 2010-01-10, superpollo <utente(a)esempio.net> wrote:
> Stachu 'Dozzie' K. ha scritto:
>> On 2010-01-10, superpollo <utente(a)esempio.net> wrote:
>>> superpollo ha scritto:
>>>> hi.
>>>>
>>>> i have a text file, and i just wanted to get, say lines 3 thru 7, or
>>>> just line 7. my first guess is:
>>>>
>>>> cat | tail -n+3 | head -n+$((7-3+1))
>>> or:
>>>
>>> cat | tail -n+7 | head -n+1
>>
>> What is this cat for? Is it doing anything useful, regarding that tail
>> can read file as well?
>>
>
> just a matter of style i think. are there performance drawdacks?

Of course there are. fork()+exec() (executing external command) is
a big, big overhead. When you run the script once per hour you will not
notice that, but if you run script in a loop with thousands of
iterations removing one more exec() will make loop run much faster.

>> And why using tail|head combination when there are awk and sed which can
>> do the same without two processes?
>>
>
> can you explain please how can i use sed? or awk?

You know, there was post with that. And even then, there's
documentation, like `man awk' and `man sed'. The manuals should be
primary source of knowledge about commands in unices.

--
Secunia non olet.
Stanislaw Klekot
From: superpollo on
Stachu 'Dozzie' K. ha scritto:
> On 2010-01-10, superpollo <utente(a)esempio.net> wrote:
>> Stachu 'Dozzie' K. ha scritto:
>>> On 2010-01-10, superpollo <utente(a)esempio.net> wrote:
>>>> superpollo ha scritto:
>>>>> hi.
>>>>>
>>>>> i have a text file, and i just wanted to get, say lines 3 thru 7, or
>>>>> just line 7. my first guess is:
>>>>>
>>>>> cat | tail -n+3 | head -n+$((7-3+1))
>>>> or:
>>>>
>>>> cat | tail -n+7 | head -n+1
>>> What is this cat for? Is it doing anything useful, regarding that tail
>>> can read file as well?
>>>
>> just a matter of style i think. are there performance drawdacks?
>
> Of course there are. fork()+exec() (executing external command) is
> a big, big overhead. When you run the script once per hour you will not
> notice that, but if you run script in a loop with thousands of
> iterations removing one more exec() will make loop run much faster.
>

thanks

>>> And why using tail|head combination when there are awk and sed which can
>>> do the same without two processes?
>>>
>> can you explain please how can i use sed? or awk?
>
> You know, there was post with that. And even then, there's
> documentation, like `man awk' and `man sed'. The manuals should be
> primary source of knowledge about commands in unices.
>

ok

bye

From: mop2 on
On Sun, 10 Jan 2010 10:15:10 -0200, superpollo <utente(a)esempio.net> wrote:

> hi.
>
> i have a text file, and i just wanted to get, say lines 3 thru 7, or
> just line 7. my first guess is:
>
> cat | tail -n+3 | head -n+$((7-3+1))
>
> but can it be made better?



$ p(){ sed -n $1${2//$2/,$2}p;}
$ seq 9
1
2
3
4
5
6
7
8
9
$ seq 9|p 3 7
3
4
5
6
7
$ seq 9|p 7
7
$
From: superpollo on
mop2 ha scritto:
> On Sun, 10 Jan 2010 10:15:10 -0200, superpollo <utente(a)esempio.net> wrote:
>
>> hi.
>>
>> i have a text file, and i just wanted to get, say lines 3 thru 7, or
>> just line 7. my first guess is:
>>
>> cat | tail -n+3 | head -n+$((7-3+1))
>>
>> but can it be made better?
>
>
>
> $ p(){ sed -n $1${2//$2/,$2}p;}
> $ seq 9
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> $ seq 9|p 3 7
> 3
> 4
> 5
> 6
> 7
> $ seq 9|p 7
> 7
> $

beautiful.

i guess i must study sed better (i only use it for s///).

bye

From: Steven J Masta on
superpollo wrote:
<snip>
>
> beautiful.
>
> i guess i must study sed better (i only use it for s///).

Give this a view:
http://sed.sourceforge.net/

Steve