Advertisement
linuxninjas

rcg.pl

Jan 3rd, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.70 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement