in reply to simple (in theory) regexp question

(In the spirit of TIMTOWDY.) Or if you want to be sloppy and short:

% perl -i -pe 's/^--(.*)\n//g' your_file

update: Please see Juerd's response below for the proper response to the author's question.

christina (not that I want to be sloppy and short)

Replies are listed 'Best First'.
Re: Re: simple (in theory) regexp question
by CukiMnstr (Deacon) on Apr 14, 2002 at 20:44 UTC
    % perl -i -pe 's/^--(.*)\n//g' your_file

    hm. that would delete every line that starts with two dashes (the original poster wanted to keep those lines).

    Update: removed the 'm' modifier bit, since the code was acting on the file, instead of acting on the 'slurped' file.

    hope this helps,

      . also, you want the 'm' modifier for the s/// operator, since the whole file is read into a scalar

      Which is not true with -pe without an alternative line ending. The file is read line-by-line.

      the original poster wanted to keep those lines

      So you're doing the exact opposite. I'm sure that'll help. Sigh. How about:

      perl -i -pe'$_ = "" unless /^--/ or !/\S/'
      which does what the original poster wants (If I understood correctly).

      Update - This was meant to be a reply to the parent of the node I replied to. This node's parent didn't have the code indented in a way I recognised as being a quote, and I didn't view the message in its context when I replied. To everyone who cites: please use <blockquote>. I use <p><blockquote><em> quote </em></blockquote></p><p> answer </p>, and even have that in my signature for ease of use.

      - Yes, I reinvent wheels.
      - Spam: Visit eurotraQ.
      

          which does what the original poster wants (If I understood correctly).

        I think you did. I think I was hasty :)