Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!mcnc!ncsu!uvacs!rwl From: rwl@uvacs.UUCP Newsgroups: net.unix Subject: Re: Berkeley 'head' script Message-ID: <1571@uvacs.UUCP> Date: Sat, 13-Oct-84 18:30:21 EDT Article-I.D.: uvacs.1571 Posted: Sat Oct 13 18:30:21 1984 Date-Received: Tue, 16-Oct-84 03:13:15 EDT Lines: 49 ------------------------------------------------------------------------------ I've just started to play with shell scripts and had to say I totally agree with Larry Tepper's complaint about the Berkeley 'head' program being binary rather than just a shell script. I guess the 'software tools' concept hasn't cought on completely... Anyway, I tried Larry's sh script and found it generally satisfactory, but it doesn't quite work right when you execute cat big_file | head.sh (where 'head.sh' is Larry's script, and 'big_file' contained ~ 30K characters). I guess the reason is that 'sed' has to do buffering when you use the 'i' command within it. Anyway, I thought I'd try my own version. For 0 or 1 file, it exec's to 'sed' for the sake of speed rather than running 'sed' and exiting. # head: print the first lines of a stream. PATH=/bin case $1 in -[0-9]*) count=`echo $1 | sed 's/-//'` ; shift ;; *) count=10 esac case $# in 0|1) exec sed ${count}q $1 ;; *) echo "==> $1 <==" ; sed ${count}q $1 ; shift esac for f in $* do echo " ==> $f <==" sed ${count}q $f done I think this version is a little faster on the whole, and it avoids the "Broken pipe" message that I get when I cat a large file through the former version. ------------------------------------------------------------------------------ Ray Lubinsky University of Virginia, Dept. of Computer Science uucp: decvax!mcnc!ncsu!uvacs!rwl AT$T: (804) 924-7280 mail: ...get serious, who mails anything these days?