A scripting question
Jing Su
jingsu-26n5VD7DAF2Tm46uYYfjYg at public.gmane.org
Fri Feb 27 06:30:59 UTC 2004
Well, here's a quick and easy way, working from where you left off...
awk 'BEGIN{
# use str to buffer up text
str="";
# two-state state machine
state=0;
}
# for handling first line
state==0 {
str=$0;
state=1;
next;
}
# for handling second line
state==1 {
print str " " $0;
str = "";
state = 0;
next;
}'
You could also do the sed to remove the "If yours was..." stuff first, and
then add an extra state to the above awk to skip over newlines...
awk 'BEGIN{
# use str to buffer up text
str="";
# three-state state machine
state=0;
}
# for handling first line
state==0 {
str=$0;
state=1;
next;
}
# for handling second line
state==1 {
print str " " $0;
str = "";
state = 2;
next;
}
# for skipping newline
state==2 {
# probably can stick in an assert that $NF==0
state = 0;
next;
}'
I know you can do state machines in sed, so that might be a faster/cleaner
way if someone knows more about sed.
-Jing
On Fri, 27 Feb 2004, Walter Dnes wrote:
> Date: Fri, 27 Feb 2004 01:16:07 -0500
> From: Walter Dnes <waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org>
> Reply-To: tlug-lxSQFCZeNF4 at public.gmane.org
> To: Toronto Linux Users Group <tlug-lxSQFCZeNF4 at public.gmane.org>
> Subject: [TLUG]: A scripting question
>
> 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 at waltdnes.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 at waltdnes.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 at waltdnes.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.
>
> 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 at waltdnes.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 ?
>
> --
> Walter Dnes <waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org>
> Email users are divided into two classes;
> 1) Those who have effective spam-blocking
> 2) Those who wish they did
> --
> 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
>
--
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