LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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-24-2012, 04:35 PM   #1
arnold.pietersen
Member
 
Registered: Jul 2012
Posts: 31

Rep: Reputation: Disabled
Extract Domain Names From E-Mail Addresses


Hi

Just checking.

What expression must I use if I want to extract domain names from a list of e-mail addresses?

Any help will be appreciated.

Kind Regards

ARNOLD
 
Old 07-24-2012, 04:53 PM   #2
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
The format of the file would be the determining factor here. A simple cut statement may be all you need. Let us know the format so we can give you the best advice.
 
Old 07-24-2012, 05:03 PM   #3
arnold.pietersen
Member
 
Registered: Jul 2012
Posts: 31

Original Poster
Rep: Reputation: Disabled
Hi Kustom42

Just normal e-mail addresses, like:

abc@xyz.co.za
jklmno.asdf@abc.org

I want the result to be:

xyz.co.za
abc.org

I hope it make sense

Kind Regards

ARNOLD
 
Old 07-24-2012, 05:20 PM   #4
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Code:
cut -d@ -f2 ./filename.txt
easy peasy.
 
1 members found this post helpful.
Old 07-24-2012, 05:22 PM   #5
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
I guess I should explain whats happening, the old teach a man to fish thing.

The cut binary can be used to cut text out of a file or stream, you specify your delimter with -d, in this case you can use @, and you specify which field to cut with -f.

So say for instance it was 1@2@3@4@5-6-7-8,

- cut -d@ -f1 would give you just the number one.
- cut -d- -f1 would give you just the number 5
- cut -d@ -f4 would give you the number 4
- cut -d- -f4 would give you the number 8


Cut by default will look for tabs as the delimter if you do not specify it with the -d option.
 
Old 07-24-2012, 05:22 PM   #6
arnold.pietersen
Member
 
Registered: Jul 2012
Posts: 31

Original Poster
Rep: Reputation: Disabled
Hi Kustom42

Thanks a million.

By the way what does the -d and the -f2 mean. You also get a -f1

Kind Regards

ARNOLD
 
Old 07-24-2012, 05:23 PM   #7
Kustom42
Senior Member
 
Registered: Mar 2012
Distribution: Red Hat
Posts: 1,604

Rep: Reputation: 415Reputation: 415Reputation: 415Reputation: 415Reputation: 415
Looks like we were posting at the same time, check the above post and let me know if you have questions.

Bookmark www.ss64.com/bash/ as well. Good reference site for your more common commands.
 
Old 07-24-2012, 05:31 PM   #8
arnold.pietersen
Member
 
Registered: Jul 2012
Posts: 31

Original Poster
Rep: Reputation: Disabled
Brilliant

Thanks a lot. Much appreciated.
 
  


Reply



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
Sending mail to addresses on the same domain, but not the same server fauxparse Linux - Software 2 11-23-2009 03:16 AM
using sed ( I think ) to extract names from e-mail address rosv Programming 4 07-07-2008 02:52 AM
Mail and domain names with Fedora Core 1 Bjorkli Linux - Networking 4 03-24-2004 02:49 PM
Configuring domain names on static IP addresses from SBC DSL redbasin Linux - Networking 4 02-10-2004 10:06 AM
Mail Server for Multiple Domain Names iamPlace Linux - Newbie 0 06-27-2003 09:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:15 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration