I'm needing to create an awk statement, that performs a few different functions on an input file I have. I'm open to other suggestions as to how best to accomplish this, I just know awk has the strength to do it...I'm just not that versed, and am having trouble.
The file has three comma delimited fields. The first field will always remain the same. The second field needs to be examined, with a couple different results pending on what is found:
1) If the field is completely non-numeric, the line should be removed from the file.
2) If the field is numeric, and less than seven digits in length, the line should be removed.
3) If field is all numeric and 7 or more digits in length, it remains as is.
3) All non-numeric characters should be removed from the field, with the third field being set as follows when the appropriate characters (upper or lower case) are found and removed
H found in field #2, field #3 is set to 1
D or DA, field3=2
E, field3=3
W or WORK, field3=4,
P, field3=6
F or FAX, field3=7
C or CELL, field3=8
B, field3=9
Any other non-numeric, field3=11
Here are a few examples of possible input lines and expected output:
51160,non-published,1 line deleted
52143,419-350-1393c,2 52143,4193501393,8
55326,440-442-3266pw,1 55326,4404423266,4
55766,do not use,3 line deleted
56290,740-464-2169c,1 56290,7404642169,8
56498,859-745-9215w,1 56498,8597459215,4
60044,240-493-7064h,3 60044,2404937064,1
61304,717-285-5827da,1 61304,7172855827,2
67223,(322)955-7266,11 67223,3229557266,11
55598,800.222.8484x203,4 55598,8002228484203,11
I don't mind making multiple passes on the file if it's needed...
All help is greatly appreciated... Thanks guys.
Start Free Trial