Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

truncate part of a variable

Status
Not open for further replies.

alarge23

Programmer
Oct 26, 2003
50
US
I have a variable called $EMAIL in my script which contains an email address in the following format:

"Billy Bob" <123456789@server.company.com>

mailx doesn't like the spaces in the email address. The email will still get to the person, but I receive errors. I want to truncate the variable $EMAIL so that it contains the value:
123456789@server.company.com

I am new to unix scripting and have struggled finding a way to do this. How can this be done?
 
There may be more elegant ways, but this will do it:
Code:
var="\"Billy Bob\" <123456789@server.company.com>"
email=$(echo $var|cut -d\< -f2|cut -d\> -f1)
[2thumbsup]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top