edit first line of long file
Wm E. Davidsen Jr
davidsen at sixhub.UUCP
Wed Oct 24 13:12:36 AEST 1990
In article <4597:Oct2321:44:2190 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
| > sed is the way.
|
| No, it's not. Try head -1 | sed 's/.../.../'; cat.
Okay, results below.
| On this
| machine, sed is more than 12 times slower than cat.
results:
Script started [y.tmp] at Tue Oct 23 23:03:14 1990
$ ls -l x.tmp
-rw-r--r-- 1 davidsen users 143405 Oct 23 23:01 x.tmp
$ time cat x.tmp > /dev/null
real 0m0.50s
user 0m0.00s
sys 0m0.36s
$ time sed '1s/foo/bar/' x.tmp > /dev/null
real 0m2.20s
user 0m1.42s
sys 0m0.40s
$ time { head -1; sed 's/foo/bar/'; cat; } < x.tmp > /dev/null
real 0m3.16s
user 0m1.86s
sys 0m0.70s
$ exit
Script ended [y.tmp] at Tue Oct 23 23:05:28 1990
How 'bout that! The overhead of all the other stuff made it slower. I
guess I'll vote for using just plain sed, because it's easier, faster,
uses less memory, etc. I didn't create a multi-megabyte file, so there
may be a break even point, but I wouldn't bet on it.
Other points:
Yes, this was ksh, so the time reported is for all processes.
/bin/time would not do as well unless you started a subshell.
Your 12:1 slower surprised the hell out of me, but you are definitely
in the right order of magnitude, perhaps even being a little nice to
sed. I really would have expected sed to just bypass the stuff after
line 1.
--
bill davidsen - davidsen at sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
sysop *IX BBS and Public Access UNIX
moderator of comp.binaries.ibm.pc and 80386 mailing list
"Stupidity, like virtue, is its own reward" -me
More information about the Comp.unix.questions
mailing list