happyv
February 21, 2007, 9:02pm
1
Hi all,
I have a file with over 10,000 line, but I would like to update/add some code number (such as 062 below) into the line with <phone number> below:
11111<name> john matin <name>
12345<phone number> 123456 <phone number>
34556 <address> 1234 lucky road <address>
11111<name> john matin <name>
12345<phone number> 062 123456 <phone number>
34556 <address> 1234 lucky road <address>
how to do it in script?
is this?
awk -F">" '{ if( match($0, "123456") ) { print $1">""062"$2">" } else { print } }' file
happyv
February 22, 2007, 12:17am
3
hi, thanks...but the phone number is not the same for each group of records....
for you idea, it only can help with the same phone number. any other suggestion for this?
So how do you determine which phone no should go with which data?
Any map like,
phone no1 for record1
phone no2 for record2
Could you please post some more examples ?
happyv
February 22, 2007, 12:57am
5
matrixmadhan:
So how do you determine which phone no should go with which data?
Any map like,
phone no1 for record1
phone no2 for record2
Could you please post some more examples ?
For example:
11111<name> john matin <name>
12345<phone number> 123456 <phone number>
34556 <address> 1234 lucky road <address>
11984<name> marry me <name>
54322<phone number> 124567680 <phone number>
345445 <address> 12 town road <address>
12211<name> peter h <name>
0245<phone number> 002983 0011 <phone number>
3400 <address> 12/f happy road <address>
For the above, all of the phone number need to add some code like "881" in front of the number.
awk -F">" '{ if( match($0, "phone") ) { print $1">""881"$2">" } else { print } }' file
and here phone is the pattern, just change that !
Am I right?
anbu23
February 22, 2007, 2:05am
7
sed "s/<phone number>/& 881/" file