Re: Curious behavior: tail, grep, cut --- Bug?

From: Chris F.A. Johnson (cfajohnson_at_gmail.com)
Date: 06/28/05


Date: Tue, 28 Jun 2005 17:22:10 -0400

On 2005-06-28, M_F_H wrote:
> Please explain this curiosity, seen on Fedora 4 and Knoppix 3.4:
>
> 1) tail -n200 /var/log/messages
> produces the last 200 lines of the main log file,
>
> 2) tail -n200 -F /var/log/messages
> produces the same as (1), but then prints any additional log entries that the
> system produces,
>
> 3) tail -n200 /var/log/messages | grep "IN=ppp0"
> finds the same lines as (1), but prints only the lines that contain the string
> "IN=ppp0",
>
> 4) tail -n200 /var/log/messages | grep IN=ppp0" | cut -b1-100
> prints the same results as (3), but only the first 100 bytes (i.e., characters)
> of each line are printed,
>
> 5) tail -n200 -F /var/log/messages | grep "IN=ppp0" | cut -b1-100
> is supposed to result in the same output as (4), and then print any additional
> lines that the log file gets that passes the grep filter. However, on every
> Linux machine I have tried, I typically get fewer lines than (4), truncated to
> the first 100 bytes of each line. And the update feature appears not to work.
> Same behavior whether one uses the -F or -f switch on tail.

    It is caused by buffering.

-- 
    Chris F.A. Johnson                     <http://cfaj.freeshell.org>
    ==================================================================
    Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
    <http://www.torfree.net/~chris/books/cfaj/ssr.html>


Relevant Pages

  • Re: reading a file
    ... given the fact that Linux Machine is available on the network .. ... LIN ... >> I am reading a log file which is being used by the Server every second ...
    (microsoft.public.dotnet.languages.vb)
  • Query regarding the owner and group of a file.
    ... I have an C++ applicationrunning on my linux machine. ... The owner and the group ... root as group. ... Then log file continues to log even after editing the log file with vi ...
    (RedHat)
  • Re: reading a file
    ... > I am reading a log file which is being used by the Server every second to ... I am writing a windows service to read this file. ... > linux machine ... ...
    (microsoft.public.dotnet.languages.vb)
  • reading a file
    ... I am reading a log file which is being used by the Server every second to ... log data. ... I am writing a windows service to read this file. ... linux machine ... ...
    (microsoft.public.dotnet.languages.vb)
  • Re: adding 1 minute to a date
    ... I then search a log file between these two dates for certain ... Is there a way to increment the minute by one, ... I have had major problems, when trying, ie: ... Shell Scripting Recipes: ...
    (comp.unix.shell)