I have a bunch of .txt
files in a directory which have information regarding dipole moment. This is how it looks like:
Dipole Moment: [D]
X: 1.2808 Y: 0.2908 Z: 1.0187 Total: 1.6622
lorem ipsum
text
that is
not
relevant
Dipole Moment: [D]
X: 1.2808 Y: 0.2908 Z: 1.0187 Total: 1.6622
more text
I want to extract the total dipole moment from these files. I am running the following script:
awk '/Dipole Moment: \[D\]/{found=1;next} found{print $NF;found=""}' *.txt > dipole_bma.txt
This script prints out 1.6622 twice. And every other Total
dipole moment in each file twice. I see that it prints it out twice because the regex appears twice in the file.
My question is, how do I print total dipole moment only once from each file?