[net.sources.d] YASS

csc@watmath.UUCP (Jan Gray) (03/16/86)

In article <620@ssc-vax.UUCP> aims@ssc-vax.UUCP (John Daley) writes:
>Why am I posting such a meager little script?  This newsgroup hasn't
>been very active lately (excluding discussions).  Anybody out there
>got a better way to do what my script does?

sed -n -e $1p -e $1q $2

Net.sources is for *useful* sources, not big useless shell scripts.

Jan Gray

john@basser.oz (John Mackin) (03/23/86)

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