[CentOS] Awk help

Spiro Harvey, Knossos Networks Ltd spiro at knossos.net.nz
Mon Jun 23 21:22:49 UTC 2008

> I have csvde dump from active directory I process on my postfix mta.
> It takes output like this:
> "CN=Curtis xxx,OU=Domain Users,OU=xxx xxx,DC=xxx-xxx,DC=local",X400:c=US\;a= \;p=xxx xxx xxx\;o=Exchange\;s=xxx\;g=xxx\;;SMTP:Cxxx at xxx-xxx.com
> and should return a relay_recipient map in the form of:
> Cxxx at xxx-xxx.com     OK
> Everything up to the awk is working, it drops the smtp: but its putting OK's all over the darn place.
> Anyone familiar enough with awk and printf that can suggest why this happens?

you can simplify that line down to:

awk 'BEGIN { FS=":" } /(smtp|SMTP)/ { printf "%-30sOK\n", $NF }' $1

the -30 will make sure that everything aligns, because with just a tab 
to separate the email addresses, you'll end up with a wonky OK column. 
-30 pads out the first column to 30 characters.

also, I recommend changing the /(smtp|SMTP)/ to just /SMTP/ because if a 
program is producing output like this from AD or LDAP, then the SMTP 
will always be caps. You risk matching other lines in the log file that 
don't match this format.

basically, this script separates a line by colons ':' and prints the 
last field if the line fed to it contains 'smtp' or 'SMTP'. The $NF is 
Number of Fields, so effectively prints the last field.

Spiro Harvey                  Knossos Networks Ltd
021-295-1923                    www.knossos.net.nz

More information about the CentOS mailing list