From: Stachu 'Dozzie' K. on 10 Jan 2010 07:31 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 10 Jan 2010 07:39 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 10 Jan 2010 08:26 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 10 Jan 2010 09:12 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 10 Jan 2010 09:21 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
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: new shell in "sh" Next: Mixet.se® Köp & Sälj - Radannonser |