Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-10-2008
Registered User
 

Join Date: Dec 2006
Posts: 11
Need to strip few letters

Hey guys..

Can experts help me in achieving my purpose..

I have a file which contains email address of some 100 to 1000 domains, I need only the domain names..

Eg: abc@yahoo.com
hd@gamil.com
ed@hotmail.com

The output should contain only

Yahoo.com
gmail.com
hotmail.com

Thanks in Advance...
Sponsored Links
  #2 (permalink)  
Old 03-10-2008
Registered User
 

Join Date: Sep 2006
Posts: 2,604
if that sample is all you have,

Code:
awk -F"@" '{.....}' file

or

Code:
cut -d "@" -f ....  file

or in shell

Code:
while IFS="@" read -r a b
do
 .....
done < "file"

  #3 (permalink)  
Old 03-11-2008
Registered User
 

Join Date: Jun 2006
Posts: 252
cat temp.txt | perl -pe 's/^.*@(.*)$/$1/'

This will handle the sample lines you provided.
  #4 (permalink)  
Old 03-11-2008
jaduks's Avatar
Registered User
 

Join Date: Aug 2007
Location: India
Posts: 177
And a sed one


Code:
$ sed 's/\(.*\)@\(.*\)/\2/' email.txt

//Jadu
  #5 (permalink)  
Old 03-11-2008
Registered User
 

Join Date: Sep 2006
Posts: 2,604
Quote:
Originally Posted by ShawnMilo View Post
cat temp.txt | perl -pe 's/^.*@(.*)$/$1/'

This will handle the sample lines you provided.
forget the cat.

Code:
perl -pe 's/^.*@(.*)$/$1/' temp.txt

  #6 (permalink)  
Old 03-11-2008
Registered User
 

Join Date: Jun 2006
Posts: 252
I always use the cat, although it's unnecessary. It adds uniformity. Some people feel the need to use as few characters as possible, or to spare the processor the extra load. But others (me included) see the cat as a convenient way to add clarity. To each his own.

I also get yelled at by my friends for usually using "sort | uniq" instead of "sort -u." Because I so often use "sort | uniq -cd" or pipe to "wc -l," it's a lot easier to always type it the same way. Also it adds clarity. The power in all the tiny tools on a *nix box is that they can be strung together to do amazingly complex tasks. It is not (and should not be) the goal of any one program to overreach and try to do too much.

However, you're correct about the cat and my friends are correct about the sort -u. I just prefer to do it my way. Stubborn, I guess. At least I finally started using CTRL+R instead of piping the history command through a grep. Usually...

ShawnMilo
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate 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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed error - using reserved letters karthikn7974 Shell Programming and Scripting 6 05-07-2008 04:25 AM
awk - delete last two letters sap4ever Shell Programming and Scripting 1 12-05-2007 09:13 AM
trim letters fed.linuxgossip Shell Programming and Scripting 10 05-15-2007 11:11 PM
transposing letters myscsa2004 Shell Programming and Scripting 4 05-12-2004 11:11 AM
capital letters GONE! blogg UNIX for Dummies Questions & Answers 8 12-11-2002 09:44 PM



All times are GMT -4. The time now is 11:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0