I'm trying to modify a text file to remove 4 lines with a given variable located in it.
For instance
zone "blah.net" {
type master;
database "mysql named blah 127.0.0.1 <> <>";
};
Someone posts to a page and has entered blah.net as the domain they'd like to remove from the file I'd like to remove the first line that it occurs in and the 3 lines below it. I have something that works via system()
system("awk '/\"$_POST[domain]$_POST[extension]/ {x=4}; {if (x) {x--} else {print}}' /tmp/named.conf > /tmp/named.modified");
but thats a pretty ugly hack to make it work, I'd prefer to open the original file named.conf and write out the file normally versus saving it to a new file. Any suggestions are greatly appreciated.