The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Email Question - two email addresses jyoung Shell Programming and Scripting 5 08-04-2008 01:00 PM
manipulate data with specific format tonet Shell Programming and Scripting 5 04-25-2008 11:24 AM
email addresses okbrowder UNIX and Linux Applications 0 04-20-2008 03:02 PM
How to delete old email addresses? Deede UNIX for Dummies Questions & Answers 1 02-03-2004 04:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-19-2008
manouche manouche is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 13
sed or other tool to manipulate data, including email addresses

I have a list of names and email addresses, like this. The <tab> markers are actually tabs.

joe.blow <tab> joe.blow@wherever.com
tom.t.hall <tab> tom.t.hall@wherever.com
john.r.smith <tab> john.r.smith@wherever.com
sally.jones <tab> sally.jones@state.or.us

I want to parse the data so that it will result in this:

joe <tab> blow <tab> joe.blow@wherever.com
tom <tab> hall<tab> tom.t.hall@wherever.com
john <tab> smith <tab> john.r.smith@wherever.com
sally <tab> jones <tab> sally.jones@state.or.us

So, all I need to do is remove the dot, if present, in the first part of each line. The second part (the email address) goes untouched.

So, I can easily use sed to go through and replace a 'character dot character', since sed looks for the first occurrence on each line, like this:

sed 's/\.[a-z]\./ /' emailfile.txt

That results in this:

joe.blow <tab> joe.blow@wherever.com
tom <tab> hall <tab> tom.t.hall@wherever.com
john <tab> smith <tab> john.r.smith@wherever.com
sally.jones <tab> sally.jones@state.or.us

If I run that sed command again, it will modify the email part (character.dot.character).

How can I get the result I need? Is sed the best tool for this?
  #2 (permalink)  
Old 02-19-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
awk?
Quote:
$ > cat file
joe.blow joe.blow@wherever.com
tom.t.hall tom.t.hall@wherever.com
john.r.smith john.r.smith@wherever.com
sally.jones sally.jones@state.or.us

$> t.awk
joe blow joe.blow@wherever.com
tom t hall tom.t.hall@wherever.com
john r smith john.r.smith@wherever.com
sally jones sally.jones@state.or.us
$ >
Code:
awk -F'\t' '{ 
    split( $1,arr, ".")
    for(i=1; arr[i]>""; i++) {printf("%s\t",arr[i])}
    print $2
             } ' file
  #3 (permalink)  
Old 02-19-2008
ynixon ynixon is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 57
try this
Code:
sed 's/\.[[:alpha:]]\.\(.*\)$/ \1#/;/#/!s/\.\(.*\)$/ \1/;s/#$//' emailfile.txt
  #4 (permalink)  
Old 02-19-2008
ynixon ynixon is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 57
Wink

Quote:
Originally Posted by jim mcnamara View Post
awk?

Code:
awk -F'\t' '{ 
    split( $1,arr, ".")
    for(i=1; arr[i]>""; i++) {printf("%s\t",arr[i])}
    print $2
             } ' file
this is the right syntax for awk:
Code:
awk -F'\t' '{
   split( $1,arr, ".")
   if ( 3 in arr ) 
      { printf("%s %s\t",arr[1],arr[3]) } 
   else 
      { printf("%s %s\t",arr[1],arr[2]) }  
   print $2
            } ' emailfile.txt
since the given output is exactly as requested
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 On




All times are GMT -4. The time now is 05:13 AM.


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-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0