edit first line of long file

Cameron Paine cbp at foster.avid.oz.au
Fri Oct 26 02:58:20 AEST 1990


In <1990Oct25.154444.12966 at foster.avid.oz.au>, I suggested trying
something like:

>	(line | sed 's/root/ROOT/'; cat) < /etc/passwd

Then, in <568 at inews.intel.com> bhoughto at cmdnfs.intel.com (Blair P. Houghton)
countered with:

>sed is the way.  it's not that much slower than cat (0.9
>seconds cpu vs. 0.0, but the perceived time was about a
>second either way and computed to 0:00).  [...]

and I felt a bit miffed. :-) So, I did a little experiment. The results
were interesting. I took a medium-sized file that many of you will
recognise:

	2129132 Oct 26 01:45 /usr/local/lib/news/ctl/history

The top line of which looks something like:

	<stuff>	649108360~66386160	 news.announce.conferences/494

and time(1)ed the following three commands:

(line | sed 's/announce/changed/'; cat) < /usr/local/lib/news/ctl/history

real     2:11.4
user        0.3
sys        18.9

sed '1s/announce/changed/' < /usr/local/lib/news/ctl/history

real     7:22.1
user     1:35.9
sys        30.8

(line | sed 's/announce/changed/'; cat -u) < /usr/local/lib/news/ctl/history

real     1:53.8
user        0.2
sys        19.9

If we ignore the third command (which is a minor variation on the first)
we find that the first is 3.36 (real) times faster and 320 (user) times
more efficient. I'm too lazy to trial it dozens of times on a variety of
hosts but I think you'll get the general idea...

Cameron
-- 
cbp at foster.avid.oz - ACSnet
cbp at foster.avid.oz.au - Internet
...!{hplabs,mcvax,nttlab,ukc,uunet}!munnari!foster.avid.oz.au!cbp - UUCP



More information about the Comp.unix.questions mailing list