Extract email address from line
[1/7] from: shuntera::gmail::com at: 6-Apr-2005 12:54
I have a log file form one of my servers that contains a bunch of
text, but each line pertains to a user and somewhere in the line there
will be his/her email address. The lines looks something like this:
blah blah blah blah [user1--company--com] blah blah blah
blah blah [user2--company--com] blah blah blah
blah blah blah blah [user3--company] blah blah
Because there is no fixed rule about where the email address appears
in the line I can't use the parse tools I normally use in a log when
everything is in fixed position.
The unique thing about the email address is that it is the only thing
that will have an ['--'] in the middle of it.
I want to send an email to these users to tell them when the system is
going to be down, how can I extract the email address from each line?
Regards.
Stuart
[2/7] from: dwhiting:europa at: 6-Apr-2005 10:23
Hi Stuart,
On Wednesday, April 6, 2005 you wrote:
> I want to send an email to these users to tell them when the system is
> going to be down, how can I extract the email address from each line?
Not elegant, but this skeleton works:
> log: [
> "blah blah blah blah [user1--company--com] blah blah blah"
<<quoted lines omitted: 9>>
> ]
> ]
HopeThisHelps,
Dick, who STILL checks in every now 'n then;-)
--
Homepage: http://www.europa.com/~dwhiting Last Updated: February 14, 2003
[3/7] from: ammon:johnson::gmail at: 6-Apr-2005 11:14
foreach line read/lines %log-file.txt [
email: find line "@"
if email [return copy/part find/reverse email " " find email " "]
]
That should catch the majority of the cases...
HTH!!
~~Ammon ;~>
On Apr 6, 2005 10:54 AM, Stuart Hunter <[shuntera--gmail--com]> wrote:
[4/7] from: shuntera::gmail::com at: 6-Apr-2005 13:42
Perfect guys, thanks.
Stuart
On Apr 6, 2005 1:14 PM, Ammon Johnson <[ammon--johnson--gmail--com]> wrote:
[5/7] from: greggirwin::mindspring::com at: 6-Apr-2005 12:05
Hi Stuart,
>> > Because there is no fixed rule about where the email address appears
>> > in the line I can't use the parse tools I normally use in a log when
>> > everything is in fixed position.
Another approach would be to use block parsing.
foreach line lines [
parse to block! line [any [set mail email! break | any-type!]]
if mail [
; send mail
]
]
to block! *can* fail with invalid data (e.g. 1xr will try to become a
pair! which it can't do, so you have to weigh that risk.
-- Gregg
[6/7] from: hallvard:ystad:oops-as:no at: 6-Apr-2005 22:16
You could also try this:
source: {
blah blah blah blah [user1--company--com] blah blah blah
blah blah [user2--company--com] blah blah blah
blah blah blah blah [user3--company] blah blah
}
lines: difference parse/all source "^/" [""]
foreach line lines [
words: parse line none
foreach word words [ if email? load word [ print join "Current user is: " word ] ]
]
Hallvard
Dixit Stuart Hunter (18.54 06.04.2005):
[7/7] from: ptretter::charter::net at: 7-Apr-2005 18:25
data: []
foreach line read/lines %log-file.txt [if not empty? line [append data first
find to-block line email!]
Paul
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted