Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!munnari!basser!john From: john@basser.oz (John Mackin) Newsgroups: net.sources.d Subject: Re: YASS (yet another shell script) Message-ID: <553@basser.oz> Date: Sun, 23-Mar-86 08:53:16 EST Article-I.D.: basser.553 Posted: Sun Mar 23 08:53:16 1986 Date-Received: Tue, 25-Mar-86 05:23:12 EST References: <620@ssc-vax.UUCP> Reply-To: john@basser.oz (John Mackin) Distribution: net Organization: Dept of Comp Sci, Uni of Sydney, Australia Lines: 34 Summary: not 'head'! In article <620@ssc-vax.UUCP> in net.sources, aims@ssc-vax.UUCP (John Daley) writes: > This is a 'simple' little shell script I whipped up, out of need, to > print a specific line of a specific file. Yes, I chose to use the B > shell, but it gets the job done, right?. [essentially:] > head -$1 $2 | tail -1 > Anybody out there got a better way to do what my script does? Yes. Not to put too fine a point on it, and not meaning to be insulting, but this is terrible. First of all, it's intensely non-portable. Many systems do not have ``head'', which is a Berkeley-ism. Furthermore, imagine something like "line 4160 /usr/lib/news/log". How much data is going to go down the pipe? A lot. A hell of a lot. Scandalously inefficient. A much more efficient way to print one line of a file, given its number (as $1, filename as $2), which should be portable to every UNIX system, is the following: sed -n -e $1p -e $1q $2 And you can surround that with as much sugar as you like. John Mackin, Basser Department of Computer Science, University of Sydney, Sydney, Australia seismo!munnari!basser.oz!john john%basser.oz@SEISMO.CSS.GOV