rwl@uvacs.UUCP (10/14/84)
------------------------------------------------------------------------------ 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?
thoth@tellab2.UUCP (Marcus Hall) (10/19/84)
In article <1571@uvacs.UUCP> rwl@uvacs.UUCP writes: > 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. But the Berkeley 'head' program *DOES* give the "Broken pipe" message, so does this mean that this is no longer compatible? :-) marcus hall ..!ihnp4!tellab1!tellab2!thoth -- marcus hall ..!ihnp4!tellab1!tellab2!thoth
wls@astrovax.UUCP (William L. Sebok) (10/24/84)
"head" is used enough here to justify making it a C program. I really don't see how one gains any clarity by replacing a perfectly good short C program with a complicated shell script using sed. I think that the latter is much harder to understand. And also slower if any Unix zealots out there still care about performance. -- Bill Sebok Princeton University, Astrophysics {allegra,akgua,burl,cbosgd,decvax,ihnp4,noao,princeton,vax135}!astrovax!wls