Linux Highlighting Tail

Some Windows users will know BareTail, they know the power of the highlighting... I wanted this on Linux too!

Usage

The syntax of this program is the same as the linux tail, it passes all arguments to tail.

Extra option: --highlight

Value: <color>:<search text>

Where: <color> is one of 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan' or 'white' <search text> is the text to be highlighted

This parameter can be specified multiple times.

Source

#!/usr/bin/perl
use Getopt::Long qw(:config pass_through);
 
my %colors =
(
   'red'     => '41;37;1m',
   'green'   => '42;37;1m',
   'yellow'  => '43;30;1m',
   'blue'    => '44;37;1m',
   'magenta' => '45;37;1m',
   'cyan'    => '46;30;1m',
   'white'   => '47;30;1m'
);
 
my @highlights;
GetOptions ("highlight=s" => \@highlights);
 
my $tailargs;
for(my $c = 0; $c < scalar(@ARGV); $c++)
{
   $tailargs .= ' ' . $ARGV[$c];
}
 
my $highlightargs;
for(my $c = 0; $c < scalar(@highlights); $c++)
{
   my @data   = split(/:/, $highlights[$c], 2);
   my $color  = $colors{$data[0]};
   my $search = $data[1];
 
   $highlightargs .= "s/(^.*$search.*\$)/\\033\\[$color\$1\\033[0m/gi; ";
}
 
my $cmd = 'tail ' . $tailargs . " | perl -p -e '" .  $highlightargs . "'";
#print 'executing: ' . $cmd . "\r\n";
system($cmd);
-
- Views - Page - Discussion - View source - History -
- Personal tools - Log in -
- Special - Special pages -