Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to separate elements from an email address

Posted on 2008-06-14
4
Medium Priority
?
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 84

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

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

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 …
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

722 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