Hello Great Monks,

I am writing a filter file to filter out some lines from two file and then compare them. Basically, I am using regular expressions to check for a line I want to be remove and then return 0 for such lines. I do not know which files will come in as the input. If the files have these lines they will be removed.

I have a different problem. In this filter file, I want to add code for removing lines between two specific tags. For example, if the file has

MYTAG1
line1
line2
line3
MYTAG2
line1
line2

I want to remove all line from MYTAG1 up untill MYTAG2 but not MYTAG2. So the file should look like after filtering: MYTAG2
Line1
line2

What I have currently is the following code:

<CODE>if (/^MYTAG1/ .. /^MYTAG2/){
return 0;
}

But this would remove the MYTAG2 line from the file. I do not want to remove the MYTAG2.

Would using "last" help? How to use it?

Please help!

A Learning Monk!


In reply to How do I remove lines from a file... by ginju75

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.