The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-21-2007
Registered User
 

Join Date: Sep 2006
Posts: 209
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?
Reply With Quote
Forum Sponsor
  #2  
Old 02-21-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
is this?

Code:
awk -F">" '{ if( match($0, "123456") ) { print $1">""062"$2">" } else { print } }' file
Reply With Quote
  #3  
Old 02-21-2007
Registered User
 

Join Date: Sep 2006
Posts: 209
Quote:
Originally Posted by matrixmadhan
is this?

Code:
awk -F">" '{ if( match($0, "123456") ) { print $1">""062"$2">" } else { print } }' file
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?
Reply With Quote
  #4  
Old 02-21-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
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
Could you please post some more examples ?
Reply With Quote
  #5  
Old 02-21-2007
Registered User
 

Join Date: Sep 2006
Posts: 209
Quote:
Originally Posted by matrixmadhan
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
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.
Reply With Quote
  #6  
Old 02-21-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Code:
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?
Reply With Quote
  #7  
Old 02-22-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
sed "s/<phone number>/& 881/" file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:41 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0