I want to replace a line which is 2 lines before the match/pattern but this match pattern is also getting repeated for 5 times in file and I want this replacement should happen only before the 5th match. For eg:
Input file
</alarmSpecification>
<alarmSpecification active="yes">
<moduleId>PSC-Task1111</moduleId>
<errorCode>444</errorCode>
</alarmSpecification>
<alarmSpecification active="yes">
<moduleId>PSC-Task2222</moduleId>
<errorCode>444</errorCode>
</alarmSpecification>
<alarmSpecification active="yes">
<moduleId>PSC-Task3333</moduleId>
<errorCode>444</errorCode>
</alarmSpecification>
<alarmSpecification active="yes">
<moduleId>PSC-Task4444</moduleId>
<errorCode>444</errorCode>
</alarmSpecification>
<alarmSpecification active="yes">
<moduleId>PSC-Task5555</moduleId>
<errorCode>444</errorCode>
Now I want replace "yes" to "no" in the 3rd last line. please remember line "444" is repeated 5 time in file and PSC-Task5555 is also repeated multiple times in entire file.
My requirement is in file, when we find below 2 combination of lines
<moduleId>PSC-Task5555</moduleId>
<errorCode>444</errorCode>
then replace the "yes" to "no" as below:
<alarmSpecification active="**no**">
<moduleId>PSC-Task5555</moduleId>
<errorCode>444</errorCode>
Thanks Ujjawal
<moduleId>PSC-Task5555</moduleId>\n<errorCode>444</errorCode>(with those specific values), or just trying to update the 5th<alarmSpecificationline or something else, i.e. tell us whatthe match/patternactually IS in your question.