![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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? |
|
||||
|
awk?
Quote:
Code:
awk -F'\t' '{
split( $1,arr, ".")
for(i=1; arr[i]>""; i++) {printf("%s\t",arr[i])}
print $2
} ' file
|
|
||||
|
Quote:
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
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|