head and tail provide a means to this end. Unfortunately, they seem to have been written by different people with different ideas about what would be useful, so they work a little differently.
% ypcat passwd | head bsmith:*:1243:317:Bob Smith:/home/baker-a/bsmith:/bin/csh wayne:*:182:60:Wayne Simpson:/home/wayne:/bin/csh walker:*:1791:100:Lisa Walker:/home/dogbert-a/walker:/bin/csh jim:*:1644:100:Jim Smith:/home/dogbert-a/jim:/bin/csh paul:*:1724:135:Paul Jones:/home/dilbert-a/paul:/bin/csh harry:*:1611:100:Harry Palmer:/home/pkduck-f/harry:/bin/csh alex:*:1959:100:Alex Watson:/home/alex:/bin/csh sue:*:1988:100:Sue Foo:/home/sue:/bin/csh marty:*:1318:78:Marty Taylor:/home/manfac-a/home/marty:/bin/csh
% ypcat passwd | head -2 bsmith:*:1243:317:Bob Smith:/home/baker-a/bsmith:/bin/csh wayne:*:182:60:Wayne Simpson:/home/wayne:/bin/csh
% head -2 /usr/man/man1/head.1 /usr/man/man1/tail.1 ==> /usr/man/man1/head.1 <== .\" @(#)head.1 1.17 90/02/15 SMI; from UCB 4.1 .TH HEAD 1 "9 September 1987" ==> /usr/man/man1/tail.1 <== .\" @(#)tail.1 1.14 90/02/15 SMI; from S5R2 6.2 83/09/02 .TH TAIL 1 "14 August 1989"
% ypcat passwd | tail cal:*:1492:160:Calvin Hobbes:/home/cal:/bin/csh adams:*:116:100:John Adams:/home/pkduck-b/adams:/bin/csh gary:*:1177:20:Gary North:/home/pkduck-e/gary:/bin/csh quincy:*:1092:20:Quincy Lizard:/home/triton-a/quincy:/bin/csh talbot:*:1679:75:Bob Talbot:/home/enterprise-a/cadmec/talbot:/bin/csh help:*:1034:31:Help Desk:/home/lewey-a/processor/help:/bin/csh glen:*:1543:20:Glen Carpenter:/home/pkduck-e/glen:/bin/csh brent:*:1799:706:Brent Adams:/home/dogbert-a/brent:/bin/csh lou:*:1701:30:Lou Grant:/home/pkduck-h/lou:/bin/csh adam:*:1124:317:Adam Baker:/home/lewey-d/adam:/bin/csh
% wc -l /usr/man/man1/tail.1 143 /usr/man/man1/tail.1 % tail +141 /usr/man/man1/tail.1 .LP Various kinds of anomalous behavior may happen with character special files. % tail -3 /usr/man/man1/tail.1 .LP Various kinds of anomalous behavior may happen with character special files.
Unlike with head, tail will operate on units other than lines. By adding the character "b" to the number, you can display the last blocks, and with "c" the last characters:
% tail -10c /usr/man/man1/tail.1 al files.
tail also has the unexpected function that it allows you to reverse the lines spewed. By default, with just the "-r" flag, tail displays the whole file in reverse order by line:
% cat > foo << END this is a test END % tail -r foo test a is this
tail also has the wildly useful feature that it can be told to wait around for further input to a file rather than stopping when it gets to the end. This is especially useful to monitor the progress of a process whose output you have redirected to a file:
% clearmake >& Transcript &  12688 % tail -f Transcript[the output from the clearmake will be displayed here as it arrives in "Transcript"]
One final difference between head and tail: while head will operate on multiple files, tail will not, so don't expect something like "tail foo bar biff" to show anything more than the last 10 lines of "foo".
Up to the TTTT index
Tuesday Tiny Techie Tips are all © Copyright 1996-1997 by Jeff Youngstrom. Please ask permission before reproducing any of this material.