in reply to Match pattern per line and after another one as multiline in single file opening

Use the concept of your one-liner to do everything.
#!perl -p use strict; use warnings; if ( /^\s*[#\n]/ or !s/.*{([^}]+).*$/$1/ ) { $_ = <>; last if !defined $_; redo; }

Clearly not tested on real data.

Bill
  • Comment on Re: Match pattern per line and after another one as multiline in single file opening
  • Download Code

Replies are listed 'Best First'.
Re^2: Match pattern per line and after another one as multiline in single file opening
by kennethk (Abbot) on Feb 14, 2017 at 23:44 UTC
      In that view, I would use only the OP's second program. All comments can be removed with a single substitution: $data =~ s/^\s*#.*?\n//msg;
      Bill
        I agree, though his regex also stripped empty lines, so maybe $data =~ s/^(?:\s*#.*)?\n//mg;

        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

        I know it is almost two years after, but I just want to thank you all for your suggestions. I wasn't visiting this site often in the meantime, as I have spent time on project with a strong preference for python. I think my Perl code wasn't used at the end. I remember that the original file was dhcp configuration file at RHEL5, but I don't remember what data exactly I was trying to extract at the time. Once again thanks!