Hi,

you described the flow of your program pretty well, so you have to open the file for reading (perldoc -f open) and one for writing the output to, then you read the file line by line (perldoc -f readline) in a loop (perldoc perlsyn). With every line you serach for the pattern via regex (perldoc perlre). If the pattern matches you do another pattern match or split which depends what is easier to extract the text (perldoc -f split). When you have the extracted portion you print the text using the output file handle to the output file (perldoc -f print). When you have read the entire file (end of loop) then you close both filehandles (perldoc -f close).So, you see, pretty straight forward.

When you encounter concrete problems on the way, come back and ask, because almost anybody here will help.

UPDATE: Your initial question has been changed. Please mark updates as updates otherwise all answers given by the monks may sound totally stupid as they don't fit the request seen by the others. So, the solution which comes to my mind in your case is using system and calling there sed or the perl equivalent to substitute the found line in one rush.

Best regards
McA


In reply to Re: Open a file, search for a string and fill a string in another file by McA
in thread Open a file, search for a string and fill a string in another file by ramki067

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.