Page 1 of 2 12>
Topic Options
#160149 - 2006-03-31 09:31 PM Text Extraction from a string
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
I am trying to extract an email address from a text string that I produced from Exchange 5.5.

I would like to extract the email address from the following string that is in a text file.

Code:
  
SMTP:kris.lutsock@ci.test.or.us%X400:c=US;a= ;p=MAC;o=MAC1;s=Lutsock;g=Kris;



Does anyone have advice on how to do this? I was thinking of having KiXtart search for the '@' symbol, then take the text that lies between the '@' symbol and the ':' and the '@' and the %, then create a new file with the extracted data.

Thanks for the help!
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#160150 - 2006-03-31 09:41 PM Re: Text Extraction from a string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Break On
$SO = SetOption('NoMacrosInStrings','On')
$String = 'SMTP:kris.lutsock@ci.test.or.us%X400:c=US;a= ;p=MAC;o=MAC1;s=Lutsock;g=Kris;'
$EMailAddy = Split(Split($String,'%')[0],':')[1]

$EMailAddy ?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160151 - 2006-03-31 09:51 PM Re: Text Extraction from a string
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
...... WoW ......
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#160152 - 2006-03-31 09:54 PM Re: Text Extraction from a string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
sorry it took me so long.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160153 - 2006-03-31 10:11 PM Re: Text Extraction from a string
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
"no problem." Thanks!

....W.W....
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#160154 - 2006-03-31 10:13 PM Re: Text Extraction from a string
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Quote:

"no problem." Thanks!

....W.W....




Yeah, what's 10 minutes - now had it stretched out to 15 then we might need to get our money back.

Top
#160155 - 2006-03-31 11:56 PM Re: Text Extraction from a string
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
LOL, no doubt NTDOC, no doubt....
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#160156 - 2006-04-01 12:04 AM Re: Text Extraction from a string
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
hmmm, thats some serious split-splitt'n
Top
#160157 - 2006-04-01 12:13 AM Re: Text Extraction from a string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
That's nothing compared to what Jooel has done.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160158 - 2006-04-01 12:42 AM Re: Text Extraction from a string
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
Quote:

That's nothing compared to what Jooel has done.



My fear for you guys just got bigger.. if splitting that was so easy... I really don't wish to know (right now =)

Just to do an echo on your split;

wait.. nevermind. First I'll get my brain to function before I 'speak'..


Edited by ewook (2006-04-01 12:58 AM)
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#160159 - 2006-04-01 12:50 AM Re: Text Extraction from a string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The first Split($String,'%') (inside) creates an array:
'SMTP:kris.lutsock@ci.test.or.us','X400:c=US;a= ;p=MAC;o=MAC1;s=Lutsock;g=Kris;'

The second Split(Split($String,'%')[0],':') (outside creates a smaller array:
'SMTP','kris.lutsock@ci.test.or.us'
The [0] and [1] simply denote which elements in the arrays to use.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160160 - 2006-04-01 01:42 AM Re: Text Extraction from a string
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
I LOVE the explanation. Excellent.

I am now trying to read text strings from a file so I can use this split method on each line in the file. Can you point me in the right direction?
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#160161 - 2006-04-01 01:49 AM Re: Text Extraction from a string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If the files are small enough, you can use the ReadFile() UDF but for big files you will want to code your own loop.

Code:
Break On
$RC = SetOption('WrapAtEOL','On')
$Folder = '\\ffpadcm01\c$\WINNT\system32\msplogs\'
$LogFile = 'WS060327.log'
$RC = Open(1,$Folder + $LogFile,2)
$Line = ReadLine(1)
$PrevLine = $Line
$PrevLineArray = Split($PrevLine,',')

While @Error = 0
$LineArray = Split($Line,',')
If $LineArray[11] = ' 443' And $PrevLineArray[10] = ' -' And $LineArray[1] = $PrevLineArray[1]
$String = 'User ' + PadStr($LineArray[1],' ',10,'R') + ' Accessed ' + $PrevLineArray[9]
$String ?
EndIf
$PrevLine = $Line
$PrevLineArray = Split($PrevLine,',')
$Line = ReadLine(1)
Loop
$RC = Close(1)

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160162 - 2006-04-01 02:51 AM Re: Text Extraction from a string
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
Breakthrough BLISS!! I love this.

I was able to craft a script that extracts the email addresses from an xch5.5 export. Beats the heck out of trying to do this manually for hundreds of users. Thanks for the guidance Les, you are a gem today!

Code:
 
Break On
$SO = SetOption('NoMacrosInStrings','On')
$array = ReadFile('e:\kixtest\xchport.txt')

for each $element in $array
if left($element,5) = "SMTP:"
$EMailAddy = Split(Split($element,'%')[0],':')[1]
$RC=RedirectOutput("e:\kixtest\emailady.txt")
IF RedirectOutput("e:\kixtest\emailady.txt") = 0
$EMailAddy ?
endif
else
if left($element,7) = "CCMAIL:"
$EMailAddy = Split(Split($element,'%')[2],':')[1]
$EMailAddy ?
endif

_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#160163 - 2006-04-01 03:11 AM Re: Text Extraction from a string
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Hmmmm, you could have exported to Excel and had Excel do the forumla to give you the name too.
Top
#160164 - 2006-04-01 03:16 AM Re: Text Extraction from a string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You are missing an EndIf and the Next.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#160165 - 2006-04-03 06:21 PM Re: Text Extraction from a string
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
NTDOC, I don't know how to do this in Excel formulas, so I turned to KiXtart instead. If you have a formula recommendation please share.
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#160166 - 2006-04-03 06:22 PM Re: Text Extraction from a string
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
Les, I'm able to run the script without any errors. Can you illustrate where the missing endif and next need to go?
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#160167 - 2006-04-03 07:16 PM Re: Text Extraction from a string
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Code:
Break On
$SO = SetOption('NoMacrosInStrings','On')
$array = ReadFile('e:\kixtest\xchport.txt')

for each $element in $array
if left($element,5) = "SMTP:"
$EMailAddy = Split(Split($element,'%')[0],':')[1]
$RC=RedirectOutput("e:\kixtest\emailady.txt")
IF RedirectOutput("e:\kixtest\emailady.txt") = 0
$EMailAddy ?
endif
else
if left($element,7) = "CCMAIL:"
$EMailAddy = Split(Split($element,'%')[2],':')[1]
$EMailAddy ?
endif
EndIf
Next



Top
#160168 - 2006-04-03 07:31 PM Re: Text Extraction from a string
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

Les, I'm able to run the script without any errors.



A testament to the forgiving nature of KiX and not your coding skills.

Does make for better golf scores though.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 774 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.099 seconds in which 0.057 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org