What kind of size of file are you talking about? (i.e. is it acceptable to slurp into memory)

one way is to just read a line at a time, and skip a chunk after your marker .. then write the whole thing back out..
my @lines; open FILE, "<", "foo.txt"; while( <FILE> ){ push @lines, $_; next unless /\byourWord\b/; <FILE> for 1 .. 5; } close FILE; open FILE, ">", "foo.txt"; print FILE, @lines; close FILE;
Hmm.. that removes the 5 lines after each match .. re-reading OP it seems like it mightbe asking for just delete all the lines after the match ... using similar method:
my @lines; open FILE, "<", "foo.txt"; while( <FILE> ){ push @lines, $_; last if /\byourWord\b/; } close FILE; open FILE, ">", "foo.txt"; print FILE, @lines; close FILE;
Another option is Tie::File and a similar approach to above .. or start looping through the array, and just splice off everything after your word is found.

In reply to Re: grep and delete by davidrw
in thread grep and delete by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.