I have a file that contains the following information:

Name - John filename "LKTA_mic4.cfg"; } Name - Tim filename "LKTA_mic2.cfg"; } Name - Jane filename "LKTA_mic1.cfg"; } Name - Jim filename "LKTA_mic3.cfg"; } Name - Don filename "LKTA_mic1.cfg"; } Name - Cody filename "LKTA_mic4.cfg"; }
I need to have the script search for 'LKTA' in the line.  If it contains text, serialize the number portion starting at 1 and ending at 4.  when it hits the fifth instance of 'LKTA', start back at 1 (loop until complete basically).  If it doesn't contain the string 'LKTA', simply print the line.

The desired output would be:

Name - John filename "LKTA_mic1.cfg"; } Name - Tim filename "LKTA_mic2.cfg"; } Name - Jane filename "LKTA_mic3.cfg"; } Name - Jim filename "LKTA_mic4.cfg"; } Name - Don filename "LKTA_mic1.cfg"; } Name - Cody filename "LKTA_mic2.cfg"; }
My knowledge of Perl is limited, and the scripts I have been trying to write are a dismal failure.  I think the best method for this would be to delete the number, and then just run a serializing loop printing 1 through 4. Any help you have to offer would be very nice of you.

In reply to serialze text in a file by TheBigAmbulance

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.