Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
11-13-2009, 09:16 AM
|
#1
|
Member
Registered: Mar 2004
Posts: 89
Rep:
|
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?
|
|
|
11-13-2009, 09:25 AM
|
#2
|
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,462
|
cut -d@ -f2 emails.txt
|
|
|
11-13-2009, 09:26 AM
|
#3
|
Senior Member
Registered: Aug 2006
Posts: 2,697
|
try posting what you have tried next time.
Code:
awk -F"@" '{print $2}' file
|
|
|
11-13-2009, 09:26 AM
|
#4
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Code:
sed 's/^.*@//' filename > newfilename
If you want to keep the "@", put it between the last two slashes
|
|
|
11-13-2009, 09:29 AM
|
#5
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Q: Which is better--SED or AWK?
A: cut (at least it's the most readable.)
|
|
|
11-13-2009, 09:48 AM
|
#6
|
Senior Member
Registered: Aug 2006
Posts: 2,697
|
Quote:
Originally Posted by pixellany
A: cut (at least it's the most readable.)
|
readable because it appears "shorter"? which is more understandable, print $2 or -f2 ?
|
|
|
11-13-2009, 09:53 AM
|
#7
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
"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"
Last edited by pixellany; 11-13-2009 at 09:55 AM.
|
|
|
11-13-2009, 10:14 AM
|
#8
|
Senior Member
Registered: Aug 2006
Posts: 2,697
|
Quote:
Originally Posted by pixellany
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.
|
|
|
11-13-2009, 10:27 AM
|
#9
|
Member
Registered: Mar 2004
Posts: 89
Original Poster
Rep:
|
Thanks to you all for your help!
|
|
|
All times are GMT -5. The time now is 01:17 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|