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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

instead of 1,000 if's question 1

Status
Not open for further replies.

admoore

IS-IT--Management
May 17, 2002
224
US
I have files full of customer data with phone # info in an area where many new area codes have been added. Many, although not all, of the recods contain no area code from the days when the city had one, not four area codes. When I parse a record with a 7 instead of 10 digit number, I need to compare it to a list of exchage prefixes for the area to determin the correct area code. I could do 1 IF statement for each of the nearly 800 prefixes which I know; but, there must be a more elegant way to compare each prefix to an external file with regular expressions.

The start of my basic code structure is:
Code:
  NR>1{
	  gsub ("-","");
	  gsub ("\"","");
	  n=n+1;
	  if(length($7)==10)
		{ # split phone no w area_code
		  area_code = substr($7,1,3);
              phone = substr($7,4,7);
		}
	  else
		{
		  # compare and fix missing area_codes here		}
        

	  print n,$1,$2,Z,area_code,phone;
	}
Any suggestions would be appreciated.

-Allen
 
use awk's associative array.

Assuming all your exchangeCode->areaCode mappings are wellknow, read the mapping into awk's array.

Whenever the area code is missing, try finding it in the associative array indexed by the area code.

Give it a shot.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top