Drew Fradette

The future is already here — it's just not very evenly distributed.

Making Multple File Tails Easy to Follow

| Comments

If you have ever used tail to follow multiple files, you will notice that it can be a real pain to read what data is coming from what file. Here is some quick perl I use to make it a bit easier:

1
tail -f *error_log | perl -pe "s/==>(.*)?<==/\e[0;31m$&\e[0m/g";

You can of course extend this to a full out perl script that processes data as follows:

processor.pl
1
2
3
4
5
6
7
8
9
#!/usr/bin/perl
while ($line = <STDIN>) {
  // Process $line however you need           
  // For the above example...
  $line =~ s/==>(.*)?<==/\e[0;31m$&\e[0m/g;

  // Now print it out like a boss
  print $line;
}

Now you can just pipe whatever data you want into the above script:

1
tail -f *error_log | perl -p processor.pl

Comments