Path: utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!ncar!midway!mimsy!chris From: chris@mimsy.umd.edu (Chris Torek) Newsgroups: comp.unix.questions Subject: Re: edit first line of long file Message-ID: <27144@mimsy.umd.edu> Date: 24 Oct 90 14:02:40 GMT References: <568@inews.intel.com> <4597:Oct2321:44:2190@kramden.acf.nyu.edu> <10201:Oct2404:23:3890@kramden.acf.nyu.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 49 In various articles Dan Bernstein and Blair Houghton fight over whether (head -1 | sed "$cmd"; cat) or sed "1$cmd" is better for applying a change to line 1 of a long file (see Subject). Blair shows results for a tiny file in which sed is faster; this is not relevant unless `a few lines' is considered a long file. Dan argues that sed is `more than 12 times slower than cat'. All of this overlooks a more basic problem. Although Dan is right about the efficiency argument on most machines (on some, the I/O is slow enough that the difference between `sed' and `cat' is that `cat' simply spends more time waiting for the disk), I have to side with Blair. Use `sed' and restrict the operation to line one. The problem with `head -1;cat' is that it does not work. On many machines, head uses standard I/O, and stdio reads in a block and head prints out the first line. Then head exits, leaving the file seek pointer pointing at the second block. Cat then reads and prints blocks two through the end. At least one POSIX draft has attempted to mandate that stdio should `reset' the input seek pointer so that (head -1; cat)