Path: utzoo!attcan!uunet!bu.edu!rpi!uupsi!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.unix.questions Subject: First-line-only editing, part 2: Portable solutions Message-ID: <16471:Oct2420:13:4390@kramden.acf.nyu.edu> Date: 24 Oct 90 20:13:43 GMT Organization: IR Lines: 22 X-Original-Subject: Re: edit first line of long file As shown in my previous message, sed is much slower than a head-sed-cat combination on a particular 300K file. However, the solution I proposed, namely head -1 | sed 's/.../.../'; cat is not portable. Apparently some people's versions of head don't seek before they die, though the clone version I'm using certainly does. So the fastest portable solution I've seen is head -1 file | sed 's/.../.../'; tail +2 file which still runs up to 12x faster than sed '1s/.../.../' on very long files, with a cutoff around 40K on this Sun 4. (Note that you need to do a bit more work if your input is a pipe, though this is not covered by ``file'' in the subject line. One simple yet fast solution is to shuttle the output to a temporary file, then apply the above.) ---Dan