Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to separate elements from an email address

Posted on 2008-06-14
4
Medium Priority
?
250 Views
Last Modified: 2013-12-26
Hi,

In Bash, given a variable, $Emailaddr, with, for instance, mariolima@multisites.com.br, I need to have separate variables like:
$user with mariolima
$domain with multisites
$class with .com.br

How to accomplish it in a Bash script?

Thanks.
Mario./
0
Comment
Question by:multisites
4 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 200 total points
ID: 21787670
#!/bin/bash
Emailaddr='mariolima@multisites.com.br'
user=${Emailaddr%@*}
class=${Emailaddr##*@}
domain=${class%%.*}
class=${class#$domain}



0
 
LVL 5

Expert Comment

by:niko86
ID: 21787686
you could do it with a combination of sed and awk like this:
echo mariolima@multisites.com.br | awk -F@ '{print $2}'
#would return: multisites.com.br
 
echo mariolima@multisites.com.br | sed 's/@.*//g'
#would return mariolima

Open in new window

0
 
LVL 9

Expert Comment

by:ghostdog74
ID: 21787860

echo "mariolima@multisites.com.br" | awk -F@ '{user=$1;m=split($2,a,".");print a[1],a[2],a[3] }'

Open in new window

0
 

Author Closing Comment

by:multisites
ID: 31467299
It worked exactly as I wanted. Thanks a lot.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question