![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| change order of fields in header record | JohnMario | UNIX for Dummies Questions & Answers | 1 | 05-22-2008 11:58 AM |
| how to read record by record from a file in unix | raoscb | UNIX for Dummies Questions & Answers | 1 | 05-16-2008 03:30 AM |
| Pivot variable record length file and change delimiter | thomasr | Shell Programming and Scripting | 3 | 10-08-2007 05:40 PM |
| splitting a record and adding a record to a file | rsolap | Shell Programming and Scripting | 1 | 08-13-2007 10:58 AM |
| change record detail...in file | happyv | Shell Programming and Scripting | 5 | 03-11-2007 10:06 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
change some record item
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? |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
is this?
Code:
awk -F">" '{ if( match($0, "123456") ) { print $1">""062"$2">" } else { print } }' file
|
|
#3
|
|||
|
|||
|
Quote:
for you idea, it only can help with the same phone number. any other suggestion for this? |
|
#4
|
|||
|
|||
|
So how do you determine which phone no should go with which data?
Any map like, Code:
phone no1 for record1 phone no2 for record2 |
|
#5
|
|||
|
|||
|
Quote:
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. |
|
#6
|
|||
|
|||
|
Code:
awk -F">" '{ if( match($0, "phone") ) { print $1">""881"$2">" } else { print } }' file
Am I right? |
|
#7
|
|||
|
|||
|
Code:
sed "s/<phone number>/& 881/" file |
|||
| Google The UNIX and Linux Forums |