Hi

Quick question. I am editing a file from the command line with perl, reading the file as one string and replacing some code. I search for the string (across multiple lines) and replace it with what I need. The regexp work but the problem I have is that only the first replace is done, then the other 2 are skipped (the expression should match in 3 places). You can see the "or" in my expression. If I remove the first search term then the second one will work etc. However I cannot get all three to work.

I thought the issue would be the /g modifier but it does not seem to work. Any ideas?

perl -0777pi.bak -e 's/(instance \"(?:ta_gpmc|ta_ocm_ram|ta_ocm_rom)\" +.*register addr_match\(1\).*regfield size (?:0|6))/${1}x1f/sg' test
UPDATE: My .* were too greedy.. Should have .*?. doh!

In reply to multiple replace from cmd line by diarmuid

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.