in reply to Delete multiple lines of text from a file?


If you'd like to avoid printing lines 16-25, it could be as simple as:
perl -i.bak -ne 'print unless 16 .. 25' *.html

However, if you wish to parse out specific <div> section(s), it is best to use a well-tested module:
use XML::Twig; my $twig = XML::Twig->new( twig_handlers => { div => sub { my $class = $_->att("class") // ""; $_->delete if $class eq "topsearchbar"; }, } ); $twig->parse_html(\*DATA)->print; __END__ Each of the unwanted divs at this point <div>starts</div> with <div class="topsearchbar"> and <div>ends</div> with </div>. They are on lines 16-25 of the file.

Output:
<html><head></head><body>Each of the unwanted divs at this point <div>starts</div> with . They are on lines 16-25 of the file. </body></html>