Re: Awk to extract contact and put into pipe delimited file
Rod Smart <[email protected]> Fri, 29 Sep 2006 15:07:44 +1000
| Newsgroups | gmane.org.user-groups.mlug.main |
|---|---|
| Organization | Rohwedder Pty. Ltd. |
| Message-ID | <[email protected]> |
Geoffrey Scott wrote: >Got another curly one for the script experts amongst us... > >I need to extract contact details from emails that are sent in plain >text formatted thus: > >Sender's IP Address = 203.465.229.57 >------------------------------------------------------------------ > to : = [email protected] >------------------------------------------------------------------ > Name : = christina tamagotchi >------------------------------------------------------------------ > Business : = >------------------------------------------------------------------ > PostalAddress : = 50 carrot road >------------------------------------------------------------------ > Suburb : = land of oz >------------------------------------------------------------------ > Postcode : = 3167 >------------------------------------------------------------------ > State : = OZ >------------------------------------------------------------------ > Telephone : = >------------------------------------------------------------------ > Mobile : = 0412345565 >------------------------------------------------------------------ > Email : = [email protected] >------------------------------------------------------------------ > OptIn : = checkbox >------------------------------------------------------------------ > Submit : = Submit > > > >Now I did an awk script like this called maillist.awk: >BEGIN { FS = " :"; RS = "--------------------------------------" } > >/^Name/ { >nam = ($2) >} > >/^Business/ { >bus = ($2) >} > >/^PostalAddress/ { >post = ($2) >} > >/^Suburb/ { >suburb = ($2) >} > >/^Postcode/ { >postc = ($2) >} > >/^State/ { >state = ($2) >} > >/^Telephone/ { >tel = ($2) >} > >/^Mobile/ { >mob = ($2) >} > >/^Email/ { >mail = ($2) >print nam "|" bus "|" post "|" suburb "|" postc "|" state "|" tel "|" >mob "|" mail >} > > >But it doesn't print anything into the output file. Why would that be? >I'm guessing that it is something to do with the formatting of the >original text. Any ideas? > > > > Regards Geoff > > May be too simple, or I'm wrong, 50% chance :P The print is inside the "Email" search item /^Email/ { mail = ($2) print nam "|" bus "|" post "|" suburb "|" postc "|" state "|" tel "|" mob "|" mail } Maybe it should have been here ? /^Email/ { mail = ($2) } print nam "|" bus "|" post "|" suburb "|" postc "|" state "|" tel "|" mob "|" mail -- Rod Smart Technical Specialist Rohwedder Pty. Ltd. 53-55 Rocco Drive Scoresby 3179 Victoria Australia Tel: +61 (0)3 9763 6455 Fax: +61 (0)3 9763 7043 URL: http://www.rohwedder.com.au PLEASE NOTE: This e-mail and its content is not legally binding as long as not explicitly confirmed in writing by Rohwedder Pty Ltd. The information contained is confidential and intended for the exclusive use by the addressee designated above. If you have received this message by mistake, please contact us immediately.