arshadmehmood118 has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Merging two files
by choroba (Cardinal) on Feb 24, 2017 at 04:37 UTC | |
|
Re: Merging two files
by hippo (Archbishop) on Feb 24, 2017 at 09:24 UTC | |
|
Re: Merging two files
by Marshall (Canon) on Feb 25, 2017 at 08:26 UTC |