procmail
[Top] [All Lists]

Re: Matching repeating lines?

1997-02-10 14:33:49
On Mon, 10 Feb 1997 13:48:55 -0500 (EST),
Lars Kellogg-Stedman <lars(_at_)bu(_dot_)edu> wrote:
:What's the most efficient way of filtering lines that are repeated more
:than <n> times?
If you're willing to settle for n=1, try the "uniq" command (but don't
That would work, except that the lines aren't identical -- each one has a 
timestamp.  Uniq won't prune these lines out of the message because 
they're not really identical.

Check out the -f switch -- at least GNU uniq has this; it allows you
to skip a number of fields before comparing. 

Failing that, how about
    perl -ne '($time, $msg) = /^(\S+ +\S+ \d\d:\d\d:\d\d \S+)(.*)/;
        if ($prev eq $msg) { ++$count; } 
        else 
        { print "$time Previous message repeated $count times\n" if $count;
        $count = 0; print; }; $prev = $msg'   /var/log/messages

(Sorry for the funny indentation, I'm on a flaky PPP link.)

What does this have with Procmail to do?

/* era */

-- 
See <http://www.ling.helsinki.fi/~reriksso/> for mantra, disclaimer, etc.
* If you enjoy getting spam, I'd appreciate it if you'd register yourself
  at the following URL:  <http://www.ling.helsinki.fi/~reriksso/spam.html>

<Prev in Thread] Current Thread [Next in Thread>