LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Replacing everything before the @ symbol (https://www.linuxquestions.org/questions/linux-newbie-8/replacing-everything-before-the-%40-symbol-768905/)

tebucky 11-13-2009 08:16 AM

Replacing everything before the @ symbol
 
Hello all,

I have a list of email address's that I need to sift through to identify only the domain name.

xyz@yo.com
abs@yo.com
clahclah@test.com

I want to remove everything before the @ symbol and only print the domain name. Can anyone assist with this?

Guttorm 11-13-2009 08:25 AM

cut -d@ -f2 emails.txt

ghostdog74 11-13-2009 08:26 AM

try posting what you have tried next time.
Code:

awk -F"@" '{print $2}' file

pixellany 11-13-2009 08:26 AM

Code:

sed 's/^.*@//' filename > newfilename
If you want to keep the "@", put it between the last two slashes

pixellany 11-13-2009 08:29 AM

Q: Which is better--SED or AWK?

A: cut (at least it's the most readable.)

;)

ghostdog74 11-13-2009 08:48 AM

Quote:

Originally Posted by pixellany (Post 3755615)
A: cut (at least it's the most readable.)
;)

readable because it appears "shorter"? which is more understandable, print $2 or -f2 ? :)

pixellany 11-13-2009 08:53 AM

"print $2" just sounds like you are a counterfeiter, whereas -f2 OBVIOUSLY means the second field.....

Sorry, I know AWK is better...........;)

Actually, in the example, "cut" is confusing---it does not remove the specified data. Perhaps the command should be renamed "keep"

ghostdog74 11-13-2009 09:14 AM

Quote:

Originally Posted by pixellany (Post 3755645)
whereas -f2 OBVIOUSLY means the second field.....

only after reading cut's man page.

Quote:

Sorry, I know AWK is better...........;)
of course. cut is just cut and nothing more. awk is cut and a whole lot more

Quote:

Actually, in the example, "cut" is confusing---it does not remove the specified data. Perhaps the command should be renamed "keep"
what do you mean? it does the job. only data left is the domains.

tebucky 11-13-2009 09:27 AM

Thanks to you all for your help!


All times are GMT -5. The time now is 07:49 PM.