Ok, I've made two modifications to what I originally posted and now it works ok with your data. My original script would never have worked properly with your report file, it worked with the trivial example that I tested it on but how and ever. Here is a working version:
#!/usr/bin/perl -w use strict; my ($REPFILE, $report); undef $/; open REPFILE, "report.rpt" or die "Cant open $REPFILE: $!\n"; $report = <REPFILE>; $report =~ s/^User Report.*//mg; $report =~ s/^All Users.*//mg; $report =~ s/^User Name.*//mg; $report =~ s/^-> Token.*//mg; print $report; close REPFILE;

Addition of m modifier to the substitution.

Because we are dealing with the whole report file in one scalar it is effectively one string and the rule for ^ and $ is that they match at the start and end of a string, not a line. To get ^ and $ matching at the start and end of a line instead of a string we have to add the m modifier. Now it sees the string in $report as a series of lines delimited by \n characters.

Addition of .* to the regex to deal with the rest of the line.

By adding .* to the regex we cause it to match (i) start of line, (ii) piece of text that we're using as a tag on the line, (iii) rest of the line up to the next \n. A dot character in a regex matches any character except a newline (\n). If you want it to match a newline you can specify this using the s regex modifier. Just to top off the confusion you can actually use both the s and m modifiers on the same regex. Most people assume that they mean single-line vs multi-line but actually they mean match newlines with dot and match ^ and $ in lines not in the whole string.


In reply to (Dermot) RE: RE: RE: RE: Re: Stripping page headers by Dermot
in thread Stripping page headers 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.