Hello Perlmonks,

I need to extract the data present in input files which has unique keys in terms of Iterations, and then I have to generate the output merged data as given below. Few times, I even have to merge more files (i.e. File1, File2, File3.txt etc) Please help me in resolving this issue.

Input files:

File1.txt:
==========
Iteration 1:
0: Data: 1023 1023
1: Data: 200 1023
2: Data: 300 1023
3: Data: 250 1023
4: Data: 1023 1023

Iteration 2:
0: Data: 1023 1024
1: Data: 1023 60
2: Data: 1023 90
3: Data: 1023 100
4: Data: 1023 1023

File2.txt:
==========
Iteration 1:
0: Data: 1023 1023
1: Data: 250 1023
2: Data: 60 1023
3: Data: 99 1023
4: Data: 1023 1023

Iteration 2:
0: Data: 1023 1024
1: Data: 1023 60
2: Data: 1023 90
3: Data: 1023 100
4: Data: 1023 1023


Output:

Expected Output file with File1 and File2 is:
Output.txt
=============
Iteration1:
File1:0: Data: 1023 1023 File2:0:Data:1023 1023
File1:1: Data: 200 1023 File2:1:Data:250 1023
File1:2: Data: 300 1023 File2:2:Data:60 1023
File1:3: Data: 250 1023 File2:3:Data:99 1023
File1:4: Data: 1023 1023 File2:4:Data:1023 1023

Iteration2:
0:Data: 1023 1024 File2:0: Data: 1023 1024
1:Data: 1023 60 File2:1: Data: 1023 60
2:Data: 1023 90 File2:2: Data: 1023 90
3:Data: 1023 100 File2:3: Data: 1023 100
4:Data: 1023 1023 File2:4: Data: 1023 1023


In reply to How do I Extract contents from given input files and merge into one text file based on Unique keys present in input files by Anonymous Monk

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.