#!/usr/bin/env perl # $Id$ # greplogs - grep logs for a string. use strict; use warnings; my $html = 0; die unless @ARGV; if ($ARGV[0] eq '-html') { shift; $html = 1; } my $s = shift; die unless defined $s; my $prev_file = ''; if ($html) { print "
"; } while () { chomp; if (/$s/) { if ($ARGV ne $prev_file) { $prev_file = $ARGV; if ($html) { print "
"; } else { print "\n\n$ARGV:\n"; } } my $n = sprintf("%05d", $.); if ($html) { s%.*debug.*%$&%i; s%.*critical|error.*%$&%i; s%$s%$&%g if $s; print "$n $_\n"; } else { print " $n: $_\n"; } } } if ($html) { print ""; }