bashtail

How do I add indentation to bash tail?


When you do a tail on a long line a wrapping happens. However, when you are tailing a log it is important to see where one line ends and the other begins. So, is is possible in tail to create an identation? The wrapping, instead of starting on the column 0, would start in the column 10. For example:

this is a very long line to simulate how a line would wrap in a terminal window
suppose this is the wrapping and it is just the same line the continues here.
this is another very long line to simulate how a line would wrap in a terminal window
suppose this is the wrapping and it is just the same line the continues here.

versus

this is a very long line to simulate how a line would wrap in a terminal window
    suppose this is the wrapping and it is just the same line the continues here.
this is another very long line to simulate how a line would wrap in a terminal window
    suppose this is the wrapping and it is just the same line the continues here.

Please note that I am not trying to modify the way the line was saved to the log file, rather, to just display the line using a different format.


Solution

  • Just pipe tail to a formatter of your choice. A simple perl script should work:

    tail log-file | perl -pe 's/(.{80})/$1\n\t/g'
    

    will indent lines with a tab character. If you are doing tail -f, you'll probably want to minimize buffering with :

    tail -f log-file | perl -pe '$|=1; s/(.{80})/$1\n\t/g'