This one-liner even creates a back-up in case things go wrong!
>perl -pibak -e"$_ = qq(foo_1\nfoo_2\nfoo_3\nfoo_4\n) if /^foo_$/" xx. +txt >dir xx.txt* Volume in drive C is Windows Volume Serial Number is AE03-D45F Directory of C:\Users\Bill\forums\monks 03/09/2021 10:47 PM 57 xx.txt 03/09/2021 07:04 PM 35 xx.txtbak 2 File(s) 92 bytes 0 Dir(s) 379,932,401,664 bytes free >type xx.txt hello world foo_1 foo_2 foo_3 foo_4 foo abc
Bill

In reply to Re: How to repeat a string multiple times if found match by BillKSmith
in thread How to repeat a string multiple times if found match by suvendra123

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.