Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

rcg.pl

By: linuxninjas on Jan 3rd, 2013  |  syntax: Perl  |  size: 0.70 KB  |  views: 64  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/perl -w
  2. #
  3. #       regexp coloured glasses - from Linux Server Hacks from O'Reilly
  4. #
  5. #       eg ./rcg "fatal" "BOLD . YELLOW . ON_WHITE"  /var/adm/messages
  6. #
  7. use strict;
  8. use Term::ANSIColor qw(:constants);
  9.  
  10. my %target = ( );
  11.  
  12. while (my $arg = shift) {
  13.         my $clr = shift;
  14.  
  15.         if (($arg =~ /^-/) | !$clr) {
  16.                 print "Usage: rcg [regex] [color] [regex] [color] ...\n";
  17.                 exit(2);
  18.         }
  19.  
  20.         #
  21.         # Ugly, lazy, pathetic hack here. [Unquote]
  22.         #
  23.         $target{$arg} = eval($clr);
  24.  
  25. }
  26.  
  27. my $rst = RESET;
  28.  
  29. while(<>) {
  30.         foreach my $x (keys(%target)) {
  31.                 s/($x)/$target{$x}$1$rst/g;
  32.         }
  33.         print
  34. }