processing a file with sed and awk

Hello,

I have what is probably a simple task in text manipulation, but I just can't wrap my brain around it.

I have a text file that looks something like the following. Note that some have middle initials in the first field and some don't.

john.r.smith:john.smith@yahoo.com
george.w.bush:gwbush@whitehouse.gov
larry.doby:ldoby@hotmail.com
tom.t.hall:tom.t.hall@nashville.com

I want to end up with a file that looks something like this:

john<tab>smith<tab>john.smith@yahoo.com
george<tab>bush<tab>gwbush@whitehouse.gov
larry<tab>doby<tab>ldoby@hotmail.com
tom<tab>hall<tab>tom.t.hall@nashville.com

So, I want to split each line into two fields separated by a tab. I was able to easily do this with awk and wrote it to file.

awk -F':' '{print $1"\t"$2}' inputfile > outputfile

I want to eliminate the middle initial in field 1, if present. I can do that with sed, but how can I process only field 1 and leave field 2 intact?

Your suggestions are most welcome.

One way.

sed -e 's%\.[a-z]\.%.%' -e 's%\.%        %' -e 's%:%     %'

note the big spaces are literal tabs, which you can usually get by typing ^v<tab>

due to the limitation of sed to interprete \t as a tab..and not wanting to tupe a TAB..i am using awk..combined with sed..

this shud work for you...

sed 's/\(.*\)\.\.*\(.*\)\.\.*\(.*\)\:/\1\.\3\:/g' inputfile |nawk -F':' '{sub(/\./,"\t",$1);print $1,"\t",$2}'

cheers,
Devaraj Takhellambam

can you explain how that command works.

Thanks
S

Assuming single-character middle initials:

awk '{sub(/\..\.*/,"\t",$1)}1' FS=":" OFS="\t" filename

Use nawk or /usr/xpg4/bin/awk on Solaris.