Suppose you have a file in Unix / Mac OS X which has phone numbers data. I mean lets say I have a text file named Phones_unformatted.txt which has some phone numbers as follows :
2127841212
3458922345
7713398403
6461228847
Now I want to format the phone numbers to have a prefix maybe like a country code +44- . something like :
+44-2127841212
+44-3458922345
+44-7713398403
+44-6461228847
If you observe I need to only append the phone number with some characters in the beginning. We can achieve the same using awk.
A simple awk code will do the trick as follows :
2127841212
3458922345
7713398403
6461228847
Now I want to format the phone numbers to have a prefix maybe like a country code +44- . something like :
+44-2127841212
+44-3458922345
+44-7713398403
+44-6461228847
If you observe I need to only append the phone number with some characters in the beginning. We can achieve the same using awk.
A simple awk code will do the trick as follows :
awk '{print "+44-" $0}' Phones_unformatted.txt
Output :
+44-2127841212
+44-3458922345
+44-7713398403
+44-6461228847
Viola!
No comments:
Post a Comment