Re: Awk to extract contact and put into pipe delimited file

Robert Moonen <[email protected]> Wed, 29 Nov 2006 17:53:16 +1100
Newsgroups gmane.org.user-groups.mlug.main
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------010609090908090008090507
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

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?

Hi Geoff
An email was transmitted to the LUV list, which contains a script which
looks to be just what you want perhaps?

Message is attached.

cheers

-- 
regards
Robert G. Moonen
registered Linux user number 298132

I swear, we're working on restoring sanity, as soon as we can find the
backup tapes -- Charles Kuffner

--------------010609090908090008090507
Content-Type: message/rfc822;
 name="Attached Message"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="Attached Message"

Return-Path: <[email protected]>
Received: from lists.luv.asn.au ([131.170.184.9])
	by imta01sl.mx.bigpond.com with ESMTP
	id <20061128001930.ZZZV23132.imta01sl.mx.bigpond.com@lists.luv.asn.au>; 
	Tue, 28 Nov 2006 00:19:30 +0000
Received: by lists.luv.asn.au (Postfix, from userid 115)
	id 5ACC2BC85B7; Tue, 28 Nov 2006 11:19:01 +1100 (EST)
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from localhost (localhost.localdomain [127.0.0.1])
	by lists.luv.asn.au (Postfix) with ESMTP id D7092BC8572
	for <[email protected]>; Tue, 28 Nov 2006 11:18:51 +1100 (EST)
Received: from lists.luv.asn.au ([127.0.0.1])
	by localhost (lists [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
	id 20077-05 for <[email protected]>;
	Tue, 28 Nov 2006 11:18:46 +1100 (EST)
Received: from sjc01.juggernaut.com.au (j114-114.sjc1.ethr.net
	[216.224.114.114])
	by lists.luv.asn.au (Postfix) with ESMTP id 2D219BC8502
	for <[email protected]>; Tue, 28 Nov 2006 11:18:46 +1100 (EST)
Received: (qmail 18721 invoked from network); 28 Nov 2006 11:18:59 +1100
X-Spam-Detail: * 1.5 RCVD_IN_SORBS_DUL RBL: SORBS: sent directly from dynamic IP
	address *      [138.217.100.124 listed in dnsbl.sorbs.net]
	*  1.5 RCVD_IN_NJABL_DUL RBL: NJABL: dialup sender did non-local SMTP
	*      [138.217.100.124 listed in combined.njabl.org]
	*  1.5 MISSING_SUBJECT Missing Subject: header
	*  0.1 TO_CC_NONE No To: or Cc: header
	* -0.0 NO_RECEIVED Informational: message has no Received headers
Received: from unknown (HELO ?10.0.0.1?) (138.217.100.124)
	by 216.224.114.114 with SMTP; 28 Nov 2006 11:18:53 +1100
Mime-Version: 1.0
Message-Id: <p06230986c1912fa824e4@[10.0.0.1]>
In-Reply-To: <[email protected]>
References: <[email protected]>
Date: Tue, 28 Nov 2006 11:18:07 +1100
To: Luv Main <[email protected]>
From: Richard Archer <[email protected]>
Subject: Re: Mail Filter
Content-Type: text/plain; charset="us-ascii"
X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at luv.asn.au
X-Loop: [email protected]
X-Sequence: 13826
Errors-to: [email protected]
Precedence: list
X-no-archive: yes
List-Id: <luv-main.luv.asn.au>
List-Help: <mailto:[email protected]?subject=help>
List-Subscribe: <mailto:[email protected]?subject=subscribe%20luv-main>
List-Unsubscribe: <mailto:[email protected]?subject=unsubscribe%20luv-main>
List-Post: <mailto:[email protected]>
List-Owner: <mailto:[email protected]>
List-Archive: <http://lists.luv.asn.au/wws/arc/luv-main>

At 9:27 AM +1100 28/11/06, Roger wrote:

>I have tried gawk, perl, sh with my limited understanding of these to
>obtain the email addresses
>between the  < and > however these are recognised as regular
>expressions not text.


I have a rather ugly shell script that I use for extracting
email addresses. Dunno if it'll be any use to you. You're
certainly on your own as for extracting the subject :)

Pipe a bunch of messages into it and it'll spit out a list of
everything that looks like an email address.

grep @ |egrep -vi
"^M.*\`|mailer-daemon@|postmaster@|message-id|Original-envelope-id:| id
<" |tr "\t" " " |sed -e "s/\(@[^ <>=();\"]*\).*/\1/" |rev|sed -e
"s/\(@[^? <>=();\"]*\).*/\1/" |rev | sort -i |uniq -i

 ...R.


--------------010609090908090008090507
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline