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 09:06 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-21-2007
Registered User
 

Join Date: Sep 2006
Posts: 209
Stumble this Post!
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 (permalink)  
Old 02-21-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,572
Stumble this Post!
is this?

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

Join Date: Sep 2006
Posts: 209
Stumble this Post!
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 (permalink)  
Old 02-21-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,572
Stumble this Post!
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 (permalink)  
Old 02-21-2007
Registered User
 

Join Date: Sep 2006
Posts: 209
Stumble this Post!
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 (permalink)  
Old 02-21-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,572
Stumble this Post!
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 (permalink)  
Old 02-21-2007
Registered User
 

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

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:42 AM.


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

Content Relevant URLs by vBSEO 3.2.0