mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2005
Posts: 29
G
goth80 Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jul 2005
Posts: 29
I'd like to strip names and domains out of a flat file database with the following "exact format" and place the "names" and "domains" into separate files. All help is valued.

email:johnathonthames@bridgeportnews.com
email:corrykalb@signgraphics.com
email:jessicarhodes@scienceargifarms.com
email:joshcohen@milltonpifer.com

ie,

-------- users.txt (johnathonthames)
|
database file (email:johnathonthames@bridgeportnews.com)
|
-------- domains.txt (bridgeportnews.com)

Last edited by goth80; 26/07/05 02:39 PM.

Whats life without a little Karma?
maddkarma[dot]com
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Morning dude,

Code:
alias _strip {
  var %user = $gettok($1,1,64), %domain = $gettok($1,2,64)
  write users.txt %user
  write domains.txt %domain
}


Type /_strip [email]user@domain.com[/email] for example.

Or another way..

Code:
alias _strip {
  if ($2 == 1) {
    return $gettok($1,1,64)
  }
  if ($2 == 2) {
    return $gettok($1,2,64)
  }
}


//echo -a $_strip(user@domain.com,1) returns user
//echo -a $_strip(user@domain.com,2) returns domain.com

Note: Only use one alias to do the following, you may rename the alias. smile

-Andy

Joined: Jul 2005
Posts: 29
G
goth80 Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jul 2005
Posts: 29
Mornin SladeKraven, you seem to always be at "my" helpdesk.. lol And thats a good thing.

Question (to understand the methodology): How does the snippet know where to extract the "username" and the "domain" avoiding the "email:" and the "@".

I'd thought a regex would have to be used.

Anyways, extremely effiecient. thanks


Whats life without a little Karma?
maddkarma[dot]com
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
I'm not very good at explaining myself it only seems to confuse people but I know what I'm talking about.

64 is the ASCII number for an @ sign.

To get an ASCII number:

//echo -a $asc(@) returns 64.
//echo -a $chr(64) returns @.

/help Token Identifiers

We know that the delimiter is a @. So we use $gettok() function.

$gettok(foo@bar,1,64) returns the first token (foo) before the @ sign. $gettok(foo@bar,2,63) returns the second token (bar) after the @ sign. It wont include the @ sign in your results as we only wanted the token before and after.

A little example of why else we use Token Identifiers:

//echo -a $address($me,5) returns our address in nick!user@host format.

We want our username.

//echo -a $gettok($address($me,5),2,33) strips our nickname

Now we're left with [email]user@host.[/email]

//echo -a $gettok($gettok($address($me,5),2,33),1,64) gets our username.

Hope this helps a little.

-Andy

Joined: Jul 2005
Posts: 29
G
goth80 Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jul 2005
Posts: 29
You're a great illustrator with words SladeKraven smile) Because I now understand how it does it (even the nested gettoken). Just need one thing clarified.

Why use the ? symbol in the:
$gettok(foo@bar,2,63)

That should do it for me. Then I'm out to the /help. Good looking out.

Last edited by goth80; 26/07/05 03:54 PM.

Whats life without a little Karma?
maddkarma[dot]com
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
What ? symbol?

Btw, for the username, since you have "email:" before it, you need to do this:

replace:
$gettok($1,1,64)

with:
$gettok($gettok($1,1,64),2,58)


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
If you use the ASCII number 63 in a $gettok() call to get the first, second, third, etc token you'd need to include the ? in it.

The ASCII number can be anything you want, it can be 33-90 or 91-160 etc.

A $gettok() call with a ? in it.

//echo -a $gettok(Hello?World?How?Are?You,0,63) returns 5, there are 5 tokens/words.

//echo -a $gettok(Hello?World?How?Are?You,1,63) returns Hello

//echo -a $gettok(Hello?World?How?Are?You,1-2,63) returns Hello?World the 1-2 means we want the first to second token.

//echo -a $replace($gettok(Hello?World?How?Are?You,1-2,63),$chr(63),$chr(32)) returns Hello World.

-Andy

Joined: Jul 2005
Posts: 29
G
goth80 Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jul 2005
Posts: 29
Code:
  SladeKraven has already anwsered my question above while i wrote this


so as i understand it using
$gettok(foo@bar,2,63) returns the second token (bar) after the @
would ignore any token/special character or just one. hmm.

No need to clutter you excellent work with further answers im in the /help Token Identifiers section as i type. Thanks again SladeKraven and Riamus2 for your valued help


----------

And thanks for the modification. The flat file is in that exact format "email:josespinoza@triplecheck.com" and I needed to extract user and domain out of it. Good looking out Riamus2

Last edited by goth80; 26/07/05 04:27 PM.

Whats life without a little Karma?
maddkarma[dot]com
Joined: Jul 2005
Posts: 29
G
goth80 Offline OP
Ameglian cow
OP Offline
Ameglian cow
G
Joined: Jul 2005
Posts: 29
smile))
Couldnt keep it to myself.
/help Token Identifiers
An Oustanding read!


Whats life without a little Karma?
maddkarma[dot]com

Link Copied to Clipboard