![]() |
|
|
google unix.com
|
|||||||
| Forums | Casino | Register | Forum Rules | Links | Albums | FAQ | Members List | 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 |
| Processing a CSV file | janemary.a | High Level Programming | 1 | 05-11-2007 06:27 AM |
| Have a shell script check for a file to exist before processing another file | heprox | Shell Programming and Scripting | 3 | 11-14-2006 02:26 AM |
| File processing on perl | garric | Shell Programming and Scripting | 2 | 09-01-2006 11:25 PM |
| processing line in file | fablef00 | Shell Programming and Scripting | 8 | 01-23-2006 10:41 AM |
| Processing a text file | TheCrunge | UNIX for Dummies Questions & Answers | 1 | 11-09-2005 10:47 AM |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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. |
| Sponsored Links |
|
|||
|
there u go
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 |
![]() |
| Bookmarks |
| Tags |
| None |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|