home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / question / 12957 < prev    next >
Encoding:
Text File  |  1992-11-06  |  2.1 KB  |  61 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!ukma!netsys!pagesat!spssig.spss.com!news.oc.com!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: Where's head?!
  5. Originator: tchrist@pixel.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1992Nov5.195726.9641@news.eng.convex.com>
  8. Date: Thu, 5 Nov 1992 19:57:26 GMT
  9. Reply-To: tchrist@convex.COM (Tom Christiansen)
  10. References: <291@procor.UUCP>
  11. Nntp-Posting-Host: pixel.convex.com
  12. Organization: Convex Computer Corporation, Colorado Springs, CO
  13. X-Disclaimer: This message was written by a user at CONVEX Computer
  14.               Corp. The opinions expressed are those of the user and
  15.               not necessarily those of CONVEX.
  16. Lines: 43
  17.  
  18. From the keyboard of jamesm@procor.dialogic.com (Mark James):
  19. :I suppose I've just been spoiled by Berkenix, but when I recently
  20. :began using Interactive's System V Release 3.2 product, I was
  21. :shocked to discover that the program 'head' does not exist, nor
  22. :does it appear anywhere in the documentation.  It's not even in
  23. :/usr/ucb, although there is a 'tail'.
  24.  
  25. As others have sed, you can just use that.
  26.  
  27. The following head clone runs pretty quickly and 
  28. even works for "hard" files, like /vmunix.
  29.  
  30. --tom
  31.  
  32.     #!/usr/bin/perl
  33.     #
  34.     # head -- perl clone of head command, but without heads silly
  35.     #         limits regarding line lengths or binary data.  Also
  36.     #         runs faster and allows pipes ("df|") as args.
  37.     #                   tchrist@convex.com
  38.  
  39.     $num = ($ARGV[0] =~ /^-(.+)/ && shift) ? $1 : 10;
  40.     die "$0: badly formed number: $1\n" unless $num =~ /^\d+$/;
  41.  
  42.     unshift(@ARGV, '-') unless $argc = @ARGV;
  43.     while (<>) {
  44.         if ($. == 1 && $argc > 1) {
  45.             print "\n" if $deja_imprime++;
  46.             print "=> $ARGV <=\n" ;
  47.         }
  48.         if ($. <= $num) {
  49.             print;
  50.         } else {
  51.             close ARGV;
  52.         }
  53.     }
  54.  
  55. --tom
  56. -- 
  57.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  58.     "...this does not mean that some of us should not want, in a rather
  59.     dispassionate sort of way, to put a bullet through csh's head."
  60.         Larry Wall in <1992Aug6.221512.5963@netlabs.com>
  61.