Solved

How to separate elements from an email address

Posted on 2008-06-14
4
231 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 84

Accepted Solution

by:
ozo earned 50 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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 …
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now