Using sed to remove a block of text

Viewed 41577

I have a block of text that looks like this:

    <!-- BOF CLEAN -->
... a bunch of stuff 
    <!-- EOF CLEAN -->

I'd like to remove this entire block. What's the sed command?

3 Answers

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);
Related