Solved

How to separate elements from an email address

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
This article will show, step by step, how to integrate R code into a R Sweave document
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 …
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 …

705 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

16 Experts available now in Live!

Get 1:1 Help Now