I'm trying to use awk to replace a multiple string in a file. I have a repeated set of lines that I need to replace and delete. For example the file has
INSTANCE "INVX1":"physical"
"A" : "reset"
"Y" : "pp_resetbar"
INSTANCE "INVX1":"physical"
"A" : "reset"
"Y" : "pp_resetbar"
INSTANCE "INVX1":"physical"
"A" : "reset"
"Y" : "pp_resetbar"
and I want to change/replace the first two and delete the 3rd, 4th, ..., Nth
INSTANCE "INVX1":"physical"
"A" : "reset"
"Y" : "pp_resetbar_b"
INSTANCE "BUFX2":"physical"
"A" : "pp_resetbar_b"
"Y" : "pp_resetbar"
To be honest I don't even know where to start. I created a script to replace the Nth occurrence but doesn't seem work for this. See below. Any help will be more than appreciated.
awk -v search=$2 -v replace=$3 -v cnt=$4 '$0 ~ search{c++;if(c==cnt){sub(search,replace);}}1' "$file" > temp && mv temp "$file"