in reply to Merging two files
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
|
|---|