Path: utzoo!attcan!uunet!munnari.oz.au!bruce!labtam!foster!cbp From: cbp@foster.avid.oz.au (Cameron Paine) Newsgroups: comp.unix.questions Subject: Re: edit first line of long file Message-ID: <1990Oct25.165820.13706@foster.avid.oz.au> Date: 25 Oct 90 16:58:20 GMT References: <27338@shamash.cdc.com> <1990Oct25.154444.12966@foster.avid.oz.au> <568@inews.intel.com> Organization: Avid Systems Pty Ltd, Melbourne, Australia. Lines: 52 In <1990Oct25.154444.12966@foster.avid.oz.au>, I suggested trying something like: > (line | sed 's/root/ROOT/'; cat) < /etc/passwd Then, in <568@inews.intel.com> bhoughto@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: 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@foster.avid.oz - ACSnet cbp@foster.avid.oz.au - Internet ...!{hplabs,mcvax,nttlab,ukc,uunet}!munnari!foster.avid.oz.au!cbp - UUCP