LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 11-13-2009, 09:16 AM   #1
tebucky
Member
 
Registered: Mar 2004
Posts: 89

Rep: Reputation: 15
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?
 
Old 11-13-2009, 09:25 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,462

Rep: Reputation: 450Reputation: 450Reputation: 450Reputation: 450Reputation: 450
cut -d@ -f2 emails.txt
 
Old 11-13-2009, 09:26 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
try posting what you have tried next time.
Code:
awk -F"@" '{print $2}' file
 
Old 11-13-2009, 09:26 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Code:
sed 's/^.*@//' filename > newfilename
If you want to keep the "@", put it between the last two slashes
 
Old 11-13-2009, 09:29 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Q: Which is better--SED or AWK?

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

 
Old 11-13-2009, 09:48 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by pixellany View Post
A: cut (at least it's the most readable.)
readable because it appears "shorter"? which is more understandable, print $2 or -f2 ?
 
Old 11-13-2009, 09:53 AM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
"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.
 
Old 11-13-2009, 10:14 AM   #8
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by pixellany View Post
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.
 
Old 11-13-2009, 10:27 AM   #9
tebucky
Member
 
Registered: Mar 2004
Posts: 89

Original Poster
Rep: Reputation: 15
Thanks to you all for your help!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
symbol lookup error: /usr/lib/libavcodec.so.51: undefined symbol: av_crc04C11DB7 priceey Linux - Software 0 05-06-2009 09:14 AM
./firefox-bin :symbol lookup error:/lib/libgthread-2.0.so.0: undefined symbol: arulupsaras Linux - General 1 11-08-2008 05:48 AM
symbol lookup error: /usr/lib/libgtk-x11.2.0.so.0: undefined symbol:... IamI Slackware 17 02-29-2008 12:10 PM
Workaround: 'symbol lookup error: k3b: undefined symbol: lstat64' devdol Linux - Software 2 02-15-2008 04:36 AM
./firefox-bin: symbol lookup error: /usr/lib/libpango-1.0.so.0: undefined symbol: g_s cb8100 Slackware 3 10-05-2006 11:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:17 AM.

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