Sponsored Content
Top Forums Shell Programming and Scripting start searching a word from the particular record on the result of first occurence change the value Post 302689895 by NareshN on Wednesday 22nd of August 2012 08:33:56 AM
Old 08-22-2012
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

Code:
<properties> 
<add key="DeliveryWithinDay" value="False" /> 
<add key="ABC" value="23:00:00 PM" /> 
<add key="DEF" value="(GMT-06:00) " /> 
<add key="CVB" value="90" /> 
<add key="XCB" value="2" /> 
<add key="Restarts" value="0" /> 
</properties> 
<properties> 
<add key="ContactAddress" value="Home" /> 
<add key="AttemptInterval" value="10" /> 
<add key="Restarts" value="1000" /> 
<add key="DEF" value="(GMT-06:00) " /> 
<add key="CVB" value="90" /> 
<add key="RestartInterval" value="600" /> 
</properties> 
<properties> 
<add key="DeliveryNextDay" value="False" /> 
<add key="ABC" value="23:00:00 PM" /> 
<add key="DEF" value="(GMT-06:00) " /> 
<add key="CVB" value="90" /> 
<add key="XCB" value="2" /> 
<add key="Restarts" value="50" /> 
<add key="XAB" value="2" /> 
</properties>


I would like to search a word "ContactAddress"(its unique value in a file) from here onwards i want to search a word "Restarts"(multiple occurences in a file) on the first occurence of result(<add key="Restarts" value="1000" /> ) in that i want to change the value 1000 to 500).

Expected output will be

Code:
<properties> 
<add key="DeliveryWithinDay" value="False" /> 
<add key="ABC" value="23:00:00 PM" /> 
<add key="DEF" value="(GMT-06:00) " /> 
<add key="CVB" value="90" /> 
<add key="XCB" value="2" /> 
<add key="Restarts" value="0" /> 
</properties> 
<properties> 
<add key="ContactAddress" value="Home" /> 
<add key="AttemptInterval" value="10" /> 
<add key="Restarts" value="500" /> 
<add key="DEF" value="(GMT-06:00) " /> 
<add key="CVB" value="90" /> 
<add key="RestartInterval" value="600" /> 
</properties> 
<properties> 
<add key="DeliveryNextDay" value="False" /> 
<add key="ABC" value="23:00:00 PM" /> 
<add key="DEF" value="(GMT-06:00) " /> 
<add key="CVB" value="90" /> 
<add key="XCB" value="2" /> 
<add key="Restarts" value="50" /> 
<add key="XAB" value="2" /> 
</properties>

Thanks in advance
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count the number of occurence of perticular word from file

I want to count the number of occurence of perticular word from one text file. Please tell me "less" command is work in ksh or not. If it is not working then instead of that which command will work. :confused: (40 Replies)
Discussion started by: rinku
40 Replies

2. Shell Programming and Scripting

Delete all occurence of a word in one shot

i have a file called file1 cat file1 i am namish namish lives in India India and namish both are good. I want to delete all the occurences of namish in one shot,if i do it with sed i guess all the lines will be deleted containing the pattern.Suggest me any idea without AWK. Thanks... (6 Replies)
Discussion started by: namishtiwari
6 Replies

3. UNIX for Dummies Questions & Answers

search& count for the occurence of a word

Greetings, I need to search and count all the occurences of a word in all the files in a directory. Any suggestions greatly appreciated. Thanks (1 Reply)
Discussion started by: skoppana
1 Replies

4. Shell Programming and Scripting

finding the number of occurence of a word in a line

suppose i have this line abs|der|gt|dftnrk|dtre i want to count the number of "|" in this line.. how can i do that. plz help:confused: (9 Replies)
Discussion started by: priyanka3006
9 Replies

5. UNIX for Dummies Questions & Answers

counting the occurence of a word

In a file I have to count a particular word. like i need apache how many times. I tried this $ tr "\011" "\012\012"<foo1 | tr -cd "" |sort\uniq -c but I got result like this 32 apache 18 dns 12 doctor Please sugest me (4 Replies)
Discussion started by: pranabrana
4 Replies

6. Shell Programming and Scripting

Perl : Search for next occurence of a word in an array

I have an array as follows: Space: ABC Name: def Age: 22 Type: new Name: fgh Age: 34 Type: old Space: XYZ Name: pqr Age: 44 Type: new : : How can I separate the array with elements starting from Space:ABC until Space: XYZ & put them in a different array & so on... (4 Replies)
Discussion started by: deo_kaustubh
4 Replies

7. Shell Programming and Scripting

Change first occurence

I'm not getting the syntax correct to change a line only on the first occurrence: I've tried to change only the first match and I've tried to change the from the second match forward sed 's/<B>PT#/<tr><td class=\"pt1\" width=\"40%\"><B>pt#/1' $file > tmpfile.html sed ... (0 Replies)
Discussion started by: dba_frog
0 Replies

8. Shell Programming and Scripting

regex - start with a word but ignore that word

Hi Guys. I guess I have a very basic query but stuck with it :( I have a file in which I want to extract particular content. The content is between standard format like : Verify stats A=0 B=12 C=34 TEST Failed Now I want to extract data between "Verify stats" & "TEST Failed" but do... (6 Replies)
Discussion started by: ratneshnagori
6 Replies

9. Shell Programming and Scripting

How to delete last occurence of word using Linux command?

Hi all, I am trying to delete last occurrence of word using sed command. for example. I have input like this on a.id1 = b.id1 and on a.id2 = b.id2 and on a.id3 = b.id3 and and I am expecting output like this on a.id1 = b.id1 and on a.id2 = b.id2 and on a.id3 = b.id3 I just need to... (11 Replies)
Discussion started by: nsk
11 Replies
All times are GMT -4. The time now is 09:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy