I have a block of text that looks like this:
... a bunch of stuff
I\'d like to remov
To remove all the text starting from and including <!-- BOF CLEAN -->
and ending at and including <!-- EOF CLEAN -->
, use following sed command:
sed -i '/<!-- BOF CLEAN -->/,/<!-- EOF CLEAN -->/d' file_name;
Reference: Delete text or paragraph between two sections using sed
$ cat text
abc
<!-- BOF CLEAN -->
... a bunch of stuff
<!-- EOF CLEAN -->
def
$ sed '/<!-- BOF CLEAN -->/,/<!-- EOF CLEAN -->/d' text
abc
def
http://www.catonmat.net/blog/sed-one-liners-explained-part-three/
These days I am using the /s
modifier to do this. I noticed no one mentioned that. I use markup with is free of spaces too like
{bof-nf}
... a bunch of stuff
{eof-nf}
So for example, to remove this block, use
$newcontent = preg_replace("/\{bof-nf\}(.*)\{eof-nf\}\\n/s", "", $newcontent);
To keep the block but remove the tags, use
$newcontent = preg_replace("/\{bof-nf\}.*\\n/", "", $newcontent);
$newcontent = preg_replace("/\{eof-nf\}.*\\n/", "", $newcontent);