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.
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
Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 938
Rep:
cut -d@ -f2 emails.txt
11-13-2009, 09:26 AM
#3
Senior Member
Registered: Aug 2006
Posts: 2,695
try posting what you have tried next time.
Code:
awk -F"@" '{print $2}' file
11-13-2009, 09:26 AM
#4
Guru
Registered: Nov 2005
Location: Pasadena, CA
Distribution: Arch+KDE
Posts: 16,552
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
Guru
Registered: Nov 2005
Location: Pasadena, CA
Distribution: Arch+KDE
Posts: 16,552
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,695
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
Guru
Registered: Nov 2005
Location: Pasadena, CA
Distribution: Arch+KDE
Posts: 16,552
"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,695
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!
Thread Tools
Search this Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT -5. The time now is 11:42 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