removeheaders

Tom Metro <[email protected]>
Newsgroups gmane.comp.log.logwatch.devel
Message-ID <[email protected]>
I don't know if performance is at all a concern with this small script, 
but in its current state it is probably running 3 times slower than it 
needs to be. It compares the line to three regular expressions, even 
though only one should ever match. The expressions should also be 
ordered such that the most likely ones are tried first.

The diff below corrects these issues. I've only tested it with data
that matches the first expression.

Also, in this line:

  while (defined($ThisLine = <STDIN>)) {

is defined() doing anything useful? Even a blank line, due to the 
newline, will still return true.

  -Tom


--- /usr/local/src/logwatch/scripts/shared/removeheaders 
2006-01-04 16:11:43.000000000 -0500
+++ /tmp/rh     2007-06-25 13:52:31.000000000 -0400
@@ -1,3 +1,4 @@
+#!/usr/bin/perl

  ##########################################################################
  # $Id: removeheaders,v 1.16 2006/01/04 21:11:43 bjorn Exp $
@@ -16,14 +17,17 @@
  # logfile.

  while (defined($ThisLine = <STDIN>)) {
-    #First line is Solaris ID tag style -mgt
-    $ThisLine =~ s/^... .. ..:..:.. [^ ]* [^\[:]*(\[\d*\])?: \[ID \d+( 
\w+\.\w+)?] //;
-    $ThisLine =~ s/^... .. ..:..:.. [^ ]* [^\[:]*(\[\d*\])?: //;
+    $ThisLine =~ s/^... .. ..:..:.. [^ ]* [^\[:]*(\[\d*\])?: //
+
      # the following is for those logs that use the service name, but 
do not
      # append the ':' right after (for example, syslogd restart). 
Presumably
      # OnlyService is called before RemoveHeaders, so this should only 
be done
      # on the required services.
-    $ThisLine =~ s/^... .. ..:..:.. [^ ]* //;
+    or $ThisLine =~ s/^... .. ..:..:.. [^ ]* //
+
+    # Solaris ID tag style -mgt
+    or $ThisLine =~ s/^... .. ..:..:.. [^ ]* [^\[:]*(\[\d*\])?: \[ID 
\d+( \w+\.\w+)?] //;
+
      print $ThisLine;
  }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.