Dear experts, I am a new learner of Perl. I want extract some information from my output files of my calculations. I have written the following script:

#!/usr/bin/perl # 2017.02.07 # Compare Qc and Dc of gold atoms use strict; open(F1,">SI.txt"); open(F2,">SI2.txt"); print F2 "\n\n\n============================ Computed geometries (Cartesian coordinates in Angstrom), total energie +s (Hartree), Hirshfeld population QA(e) and atomic overlap distances DA(bohr) of a +ll systems given in Table SI-1 and Table SI-2. \n\n"; print F1 "\n\n\n========================== Computed Q(Au) and D(Au) of all atoms in all neutral Au clusters \n\n" +; print F1 " Atom QA DA(alpha) DA(beta) DA(total)\n"; foreach my $f(<*log>){ my $c=`grep -c "Normal term" $f`;chomp($c); my $E=`tac $f|grep -m1 "SCF Done"|awk "{print \\\$5}"`; chomp( +$E); my $Nat = `cat $f|grep -m1 "NAtoms="|awk "{print \\\$2}" `; ch +omp($Nat); my $off=$Nat+4; my $coord=`tac $f|grep -m1 -B$off " orientation:"|head + -n$Nat|tac|awk -v OFS='\t' "{print\\\$1,\\\$2,\\\$4,\\\$5,\\\$6}"`; print F2 "Molecule $f \nEnergy: $E\nGeometry:\nAtom A +tomic No. x y z\n $coord Atom +QA DA(alpha) DA(beta) DA(total)\n"; foreach my $at(1..$Nat){ my $at2=$at+1; # Get the Hirshfeld populations and atomic del +ocalziations my $QA = `tac $f|grep -m1 -B$at2 "Hirshfeld ch +arges, spin" | head -n1|awk "{print \\\$3}"`;chomp($QA); my $dalpha=`tac $f|grep -m1 -B$at2 "Atomic ave +rage delocal" |head -n1 |awk "{print \\\$3}"`; chomp($dalpha); my $dbeta=`tac $f|grep -m1 -B$at2 "Atomic aver +age delocal" |head -n1 |awk "{print \\\$4}"`; chomp($dbeta); my $dtotal=`tac $f|grep -m1 -B$at2 "Atomic ave +rage delocal" |head -n1 |awk "{print \\\$5}"`; chomp($dtotal); print F1 sprintf(" %4d %7.4f %7.4f + %7.4f %7.4f \n",$at,$QA,$dalpha,$dbeta,$dtotal); } } close(F1); close(F2);

Using my limited knowledge of Perl, I have successfully extracted what I want from my output files in two files SI.txt and SI2.txt. But I want to combine information about each molecule in one file. I don't know how to write script that combines the information into one file. File SI.txt gives me:

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

and File SI2.txt gives me:

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)

But this is what I want:

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

Please help me, if possible. I shall be very much thankful


In reply to 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.