I don't really understand the "rules" by which the output is generated from the 2 files. Can you explain more about how to generate the output from SI.txt and SI2.txt?

It could be that if you give an example of *.log files, that your desired output could be directly generated from those files without these SI.txt and SI2.txt intermediates? I don't know.

It has been a very,very long time since I used either sed or awk. There is no need for these with Perl. Anyway your grep | awk code is not helpful to me.

Update:
Without really understanding the rules, this code produces your desired output. I guess what I meant above is "tell me what is wrong with this algorithm":

#!/usr/bin/perl use strict; use warnings; ## simulate actual files ## my $SI_txt =<<END; Atom QA DA(alpha) DA(beta) DA(total) 1 1.0000 2.2238 2.6173 2.3812 1 1.3294 1.9996 1.9996 1.9996 2 -0.1098 2.2233 2.2233 2.2233 3 -0.1098 2.2233 2.2233 2.2233 4 -0.1098 2.2233 2.2233 2.2233 END my $SI2_txt =<<END; Molecule 01-Carbon-Energy.log Energy: -37.7131454546 Geometry: Atom Atomic No. x y z 1 6 0.000000 0.000000 0.000000 Atom QA DA(alpha) DA(beta) DA(total) Molecule 02-Methanide-Geometry.log Energy: -39.6946868929 Geometry: Atom Atomic No. x y z 1 6 0.000000 0.000000 0.000000 2 1 0.000000 1.084453 0.000000 3 1 -0.939164 -0.542227 0.000000 4 1 0.939164 -0.542227 0.000000 Atom QA DA(alpha) DA(beta) DA(total) END ### start of "real code" ### open my $SI, "<", \$SI_txt or die "unable to open SI.txt"; open my $SI2, "<", \$SI2_txt or die "unable to open SI2.txt"; my @SIarray; while (<$SI>) { next unless $_ =~ /\d/; #throw away header line or blank push @SIarray, $_; } while (<$SI2>) { print; if (/^\s*Atom\s+QA/) #interleave first line of SI.txt { print shift @SIarray; } } print @SIarray; __END__ Molecule 01-Carbon-Energy.log Energy: -37.7131454546 Geometry: Atom Atomic No. x y z 1 6 0.000000 0.000000 0.000000 Atom QA DA(alpha) DA(beta) DA(total) 1 1.0000 2.2238 2.6173 2.3812 Molecule 02-Methanide-Geometry.log Energy: -39.6946868929 Geometry: Atom Atomic No. x y z 1 6 0.000000 0.000000 0.000000 2 1 0.000000 1.084453 0.000000 3 1 -0.939164 -0.542227 0.000000 4 1 0.939164 -0.542227 0.000000 Atom QA DA(alpha) DA(beta) DA(total) 1 1.3294 1.9996 1.9996 1.9996 2 -0.1098 2.2233 2.2233 2.2233 3 -0.1098 2.2233 2.2233 2.2233 4 -0.1098 2.2233 2.2233 2.2233

In reply to Re: Merging two files by Marshall
in thread Merging two files by arshadmehmood118

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.