#original file
.
.
~
~
Index=2
xxx
replace #dont replace 1st occurance
yyy
Index=2
xxx
replace #substitue replace with "REPLACE"
yyy
Index=2
xxx
replace #substitue replace with "REPLACE"
yyy
Index=3
xxx
replace
yyy
Expected output file:
.
.
~
~
Index=2
xxx
replace
yyy
Index=2
xxx
REPLACE
yyy
Index=2
xxx
REPLACE
yyy
Index=3
xxx
replace
yyy
Hi,
This is the simiplified file I am working on.. I need to :
- search for 2nd occurance of a string pattern ("Index=2"in file)
- Go forward 2 lines after this
- Replace current line with new pattern (ex: "REPLACE" )
I am using awk for checking the 2nd oocurance, but dont know
how to step 2 lines forward and replace the string.
#awk.sh
/Index=2/{
mcount++
if(mcount == 2){
{print NR+2}
#need to substitute NR+2
}
}