Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting string data... 1

Status
Not open for further replies.

admoore

IS-IT--Management
May 17, 2002
224
US
I have a .csv file, which includes one field($19) which is phone # data and inconsistent...

i.e.

5205551212 -or-
520-555-1212 -or-
(520)555-1212 -or-
(520) 555-1212

And I'd like all output to be like:

(520)555-1212

I assume I need to 1st gsub out the ( ) & - then reformat the result; but, I need some help accomplishing this, please.

TIA,

-Allen
 
Try

BEGIN {
FS=OFS=","
fld=19
}
{
gsub(/[() -]/,"",$fld)
$2 = "(" substr($fld,1,3) ")" substr($fld,4,3) "-" substr($fld,8)
print
}


CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top