Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!ucsd!nosc!crash!orbit!zuhause!bruce From: bruce@zuhause.MN.ORG (Bruce Albrecht) Newsgroups: comp.sys.amiga.tech Subject: Re: Unix like 'tail -f' Message-ID: Date: 21 Jan 91 12:52:56 GMT References: <1991Jan17.034047.18447@eecs.wsu.edu> <685@caslon.cs.arizona.edu> Lines: 20 >In article <685@caslon.cs.arizona.edu> dave@cs.arizona.edu (Dave P. Schaumann) writes: >The functionality of 'tail' can be achieved quite easily. > 1) Define N == the # of lines to be displayed. > 2) Create an array of N strings, all initially the empty string. > 3) Read in the file line by line, filling in the array in a circular > fashion (ie, the N+1 line would over-write the 1st entry of the array). > 4) When EOF is reached, print out the array, from oldest to newest. > >This general outline will give a solution that only needs to read the file >once, and is reasonably economical in space. There's a tail program in the SKsh package. It can be used independently of SKsh. The above implementation may not work will if the file has lines over a an arbitary size. If you know that the input file is seekable, it's probably faster to seek to the end of the file, and read backwards, especially if the file is very big, and the tail line count is small. -- bruce@zuhause.mn.org