LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Extract Domain Names From E-Mail Addresses (https://www.linuxquestions.org/questions/programming-9/extract-domain-names-from-e-mail-addresses-4175418466/)

arnold.pietersen 07-24-2012 04:35 PM

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

Kustom42 07-24-2012 04:53 PM

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.

arnold.pietersen 07-24-2012 05:03 PM

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

Kustom42 07-24-2012 05:20 PM

Code:

cut -d@ -f2 ./filename.txt
easy peasy.

Kustom42 07-24-2012 05:22 PM

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.

arnold.pietersen 07-24-2012 05:22 PM

Hi Kustom42

Thanks a million.

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

Kind Regards

ARNOLD

Kustom42 07-24-2012 05:23 PM

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.

arnold.pietersen 07-24-2012 05:31 PM

Brilliant

Thanks a lot. Much appreciated.


All times are GMT -5. The time now is 11:08 AM.