A scripting question

Sergey Kuznetsov skuznets-WRMZ5ucGVl4BXFe83j6qeQ at public.gmane.org
Fri Feb 27 12:48:06 UTC 2004


On February 27, 2004 06:16 am, Walter Dnes wrote:
>   AWK, bash, sed, vim macro, perl, tr, whatever.  I have a remote inbox
> with clss.net, which allows me to control smtp-stage blocking by DNSbl,
> IP address, rDNS, etc.  I also get a log file.  I want to be able to re-
> format the logfile for my own statistics.  Each reject causes 3 lines to
> be written to the logfile;
>   1) Originator + destination
>   2) A TXT output, plus a message of my choosing.
>   3) A zero-length line
>
>   Here's an example.  Note that it does *NOT* really have the leading
> "> "; that's just there to prevent linewrap in this message.
>
> > Thu Feb 26 08:24:15 2004 (blaezilp-PkbjNfxxIARBDgjK7y7TUQ at public.gmane.org) ->
> > (waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org) [62.195.50.109] Certain countries (pireject-tail)
> > If yours was a legitimate email see http://www.waltdnes.org/bypass.html
> > to bypass block.
> >
> > Thu Feb 26 09:02:19 2004 (manko01-uAjRD0nVeow at public.gmane.org) -> (waltdnes at waltdnes.org)
> > [65.83.117.101] Rejected due to lack of hostname. If yours was a
> > legitimate email see http://www.waltdnes.org/bypass.html to bypass block.
> >
> > Thu Feb 26 11:27:13 2004 (dchris8816-PkbjNfxxIARBDgjK7y7TUQ at public.gmane.org) ->
> > (waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org) [67.153.220.90] Rejected email from dynamic IP.
> > If yours was a legitimate email see http://www.waltdnes.org/bypass.html
> > to bypass block.
>
>   I can get rid of the blank lines with
> grep -v "^..."
>
>   And I can get rid of the pointer to my unfiltered email address with
> sed "s/If yours was.*$//"
>
>   This leaves me with...
>
> > Thu Feb 26 08:24:15 2004 (blaezilp-PkbjNfxxIARBDgjK7y7TUQ at public.gmane.org) ->
> > (waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org) [62.195.50.109] Certain countries (pireject-tail)
> > Thu Feb 26 09:02:19 2004 (manko01-uAjRD0nVeow at public.gmane.org) -> (waltdnes at waltdnes.org)
> > [65.83.117.101] Rejected due to lack of hostname.
> > Thu Feb 26 11:27:13 2004 (dchris8816-PkbjNfxxIARBDgjK7y7TUQ at public.gmane.org) ->
> > (waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org) [67.153.220.90] Rejected email from dynamic IP.
>
>   I want to roll up the two lines for each reject into one long line
> like so.  Again, the leading "> " isn't really there.
>
> > Thu Feb 26 08:24:15 2004 (blaezilp-PkbjNfxxIARBDgjK7y7TUQ at public.gmane.org) ->
> > (waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org) [62.195.50.109] Certain countries (pireject-tail)
> > Thu Feb 26 09:02:19 2004 (manko01-uAjRD0nVeow at public.gmane.org) -> (waltdnes at waltdnes.org)
> > [65.83.117.101] Rejected due to lack of hostname. Thu Feb 26 11:27:13
> > 2004 (dchris8816-PkbjNfxxIARBDgjK7y7TUQ at public.gmane.org) -> (waltdnes at waltdnes.org) [67.153.220.90]
> > Rejected email from dynamic IP.
>
>   How do I remove every second end-of-line to achieve this ?

#!/usr/bin/perl

    open IN, "wdnes.log" or die;
    $text = join "", <IN>;
    $text =~ s/ If yours was.*$//mgi;
    $text =~ s/\n(?!\n)/ /mgi;

    print "$text";


Tested. It works.

-- 
All the Best!
Sergey Kuznetsov

Senior Software Developer
Blueprint Initiative
at Samuel Lunenfeld Research Institute
Mount Sinai Hospital
522 University Street
Phone#: (416) 596-8505 x6343
E-Mail: skuznets-WRMZ5ucGVl4BXFe83j6qeQ at public.gmane.org
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list