change some record item


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting change some record item
# 1  
Old 02-21-2007
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?
# 2  
Old 02-22-2007
is this? Smilie

Code:
awk -F">" '{ if( match($0, "123456") ) { print $1">""062"$2">" } else { print } }' file

# 3  
Old 02-22-2007
Quote:
Originally Posted by matrixmadhan
is this? Smilie

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?
# 4  
Old 02-22-2007
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 ? Smilie
# 5  
Old 02-22-2007
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 ? Smilie
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.
# 6  
Old 02-22-2007
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? Smilie
# 7  
Old 02-22-2007
Code:
sed "s/<phone number>/& 881/" file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read a lis, find items in a file from the list, change each item

Hello, I have some tab delimited text data, file: final_temp1 aname val NAME;r'(1,) 3.28584 r'(2,)<tab> NAME;r'(3,) 6.13003 NAME;r'(4,) 4.18037 r'(5,)<tab> You can see that the data is incomplete in some cases. There is a trailing tab after the first column for each incomplete row. I... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

2. Shell Programming and Scripting

Extract timestamp from first record in xml file and it checks if not it will replace first record

I have test.xml <emp><id>101</id><name>AAA</name><date>06/06/14 1811</date></emp> <Join><id>101</id><city>london</city><date>06/06/14 2011</date></join> <Join><id>101</id><city>new york</city><date>06/06/14 1811</date></join> <Join><id>101</id><city>sydney</city><date>06/06/14... (2 Replies)
Discussion started by: vsraju
2 Replies

3. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

4. Shell Programming and Scripting

start searching a word from the particular record on the result of first occurence change the value

Hi, I need a script to start searching a word from the particular record on the result of first occurence i need to change the value in that record. I have a input file like this <properties> <add key="DeliveryWithinDay" value="False" /> <add key="ABC" value="23:00:00 PM" /> <add... (5 Replies)
Discussion started by: NareshN
5 Replies

5. Shell Programming and Scripting

awk change one value in csv based on another value in the record

I've found 2 great discussions on this forum that are tied to my question, but for some reason, neither solution works for me. I have a CSV file with many records, up to 150+ at some times. Many records have a value of H in $1. For those records, I need to add today's current date in $20. I'm... (4 Replies)
Discussion started by: mrvitas
4 Replies

6. UNIX for Dummies Questions & Answers

how to find 922 record 03 or 88 not found code 922 change 922 to 904

%%START CBLOADER CBLOADER BRBAI2 000090 01,011600033,011600033,110516,0834,2,90,,2/ 02,011600033,011103093,1,110317,0834,,2/ 03,105581,,015,+00000416418,,,901,+00000000148,,,922,+000000 00354,,/ 03,113806,,015,+00000559618,,,901,+00000000096,,,922,+000000 00621,,/... (1 Reply)
Discussion started by: sgoud
1 Replies

7. UNIX for Dummies Questions & Answers

change order of fields in header record

Hello, after 9 months of archiving 1000 files, now, i need to change the order of fields in the header record. some very large, space padded files. HEADERCAS05212008D0210DOMEST01(spacepadded to record length 210) must now be 05212008HEADERCASD0210DOMEST01(spacepadded to record length 210) ... (1 Reply)
Discussion started by: JohnMario
1 Replies

8. Shell Programming and Scripting

Pivot variable record length file and change delimiter

Hi experts. I got a file (500mb max) and need to pivot it (loading into ORCL) and change BLANK delimiter to PIPE |. Sometimes there are multipel BLANKS (as a particular value may be BLANK, or simply two BLANKS instead of one BLANK). thanks for your input! Cheers, Layout... (3 Replies)
Discussion started by: thomasr
3 Replies

9. UNIX for Dummies Questions & Answers

replace item..

Hello, I have the following basic script which is remove the fielld. How can I replace another value in the field? Thx!! for file in `cat $listn.txt` do get_file -q $file grep -v '<customer-id>13000</customer-id>' $file > $file.grep done echo All processed file done!! input file:... (2 Replies)
Discussion started by: happyv
2 Replies

10. Shell Programming and Scripting

change record detail...in file

hello, I have a file with the following record: a.txt AAjohn10123403 AAmary10298411 AAcat120192a1030 AApeter094857 AAmaybb019485 I have a list called b.txt, if matched the name and it will change to new name (which is after space) john1 cancel cat12 cat12 peter peter mary1... (5 Replies)
Discussion started by: happyv
5 Replies
Login or Register to Ask a Question