LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-06-2008, 04:11 PM   #1
rosv
Member
 
Registered: Jul 2008
Distribution: Slackware, ubuntu
Posts: 53

Rep: Reputation: 15
using sed ( I think ) to extract names from e-mail address


Hi,
I'm trying to figure out how to extract names from e-mail addresses.

For example:
extract John from john.doe@nobody.com

I guess I should use sed to extract any character(s) up to the . and then store whatever I get in a new variable (it's for use in a bash script).

Sed proved to be more difficult than I thought.
Any suggestions?
 
Old 07-06-2008, 04:20 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
I'll warn, email addresses are more complex than the simple example. But for now:

echo 'tom.jones@example.com' | sed 's/^\([^.]*\)\..*$/\1/'
 
Old 07-06-2008, 09:01 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,696
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by rosv View Post
Sed proved to be more difficult than I thought.
Any suggestions?
because sed is based on regular expressions. if you are not familiar, get familiar otherwise, using simple methods (KISS) will suffice.
Code:
# echo "john@somewhere.com" | awk -F"@" '{print $1}'
john
# echo "john@somewhere.com" | cut -d@ -f1
john
 
Old 07-06-2008, 11:19 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,289

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
For your specific example

echo john.doe@nobody.com|cut -d'.' -f1
john
 
Old 07-07-2008, 02:52 AM   #5
rosv
Member
 
Registered: Jul 2008
Distribution: Slackware, ubuntu
Posts: 53

Original Poster
Rep: Reputation: 15
Thanx guys. I think I have it dialed in now.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hi,all. I have a configure file. I wanna extract something from it using sed or awt cryincold Programming 4 04-02-2008 03:42 PM
sed command extract contents withing body tag of html Fond_of_Opensource Linux - Newbie 6 06-04-2007 07:55 AM
extract the IP address from ppp0 interface culin Programming 16 04-20-2007 12:59 PM
sed to extract multiple matches in a line? mhoch3 Linux - Software 8 08-01-2005 03:32 PM
How to extract a part of a line by sed? J_Szucs Programming 2 02-15-2003 06:49 PM


All times are GMT -5. The time now is 06:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration