Solved

How to separate elements from an email address

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to monitor servers ? 4 64
CSV file copy field 1 to field 2 2 63
Powershell PGP and SFTP 1 48
script to read text file 34 33
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…

751 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