[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: reading the end of file



On Fri, Jul 24, 2009 at 12:37:51AM -0500, Ron Johnson wrote:
> On 2009-07-23 01:45, Ekkard Gerlach wrote:
>> * Francesco Pietra schrieb:
>>
>>> Hi:
>>>
>>> Is any command faster than
>>>
>>> cat filename
>>>
>>> to reach and print on screen the last page of the file?
>>
>> what kind of "file"?   tail -n 10 filename
>> makes output of last 10 lines of a file. But if there are no
>> linefeeds/ carriage return in the files, the it makes no sense. 
>>
>>   tac filename > filename_taced 
>
> Hey, cool.  I never knew that...
>
>> turns around a file, the end becomes the beginning.   head -n 10 
>> filename_taced | tac 
>
> Why use an intermediary file instead of a pipe?
>
> $ tac filename | head -n10

Well in some cases it makes a difference.  tail operating on a file
can read the file form the end rather than reading the whole file,
while with the pipe it has no choice but to receive all the data and
then return the last bit of it.

-- 
Len Sorensen


Reply to: