Hello,
I am a new programmer and currently having some difficulties writing a script. Your help will be very appreciated. In general, I have the below script running in one folder and and can get results from "OUPUT" file in the same folder. My question is I have several hundreds folder which all contain file "OUTPUT". How can I modify my below script to extract the results from all the OUTPUT file?
Thanks all in advance
#!/usr/bin/perl
# open file
open FILE, "OUTPUT";
@file = <FILE>;
close FILE;
# scan file
$stop = scalar(@file);
for ($n_line = 0; $n_line <= $stop-1; $n_line++) {
$line = $file[$n_line];
if ($line=~/trace\/3\s*(\d.\d+E\-\d+)/) {
$average_pressure=$1;
open result1, ">>../pressure.txt";
#print "$average_pressure\n";
print result1 "$average_pressure\n";
close result1;
}
if ($line=~/trace\/3\s*(\d.\d+E\+\d+)/) {
$latt_length=$1;
open result2, ">>../lattice_vector.txt";
#print "$latt_length\n";
print result2 "$latt_length\n";
close result2;
}
if ($line=~/Average cell vectors\s*r.m.s. fluctuations /) {
chomp($file[$n_line + 2]);
@matrix_line1 = split(/ +/, $file[$n_line + 2]);
chomp($file[$n_line + 3]);
@matrix_line2 = split(/ +/, $file[$n_line + 3]);
chomp($file[$n_line + 4]);
@matrix_line3 = split(/ +/, $file[$n_line + 4]);
open result2, ">>../lattice_vector_error.txt";
#print "$matrix_line1[4]\n";
print result2 "$matrix_line1[4]\n";
close result2;
}
if ($line=~/Average pressure tensor\s*r.m.s. fluctuations/) {
chomp($file[$n_line + 2]);
@matrix_line1 = split(/ +/, $file[$n_line + 2]);
chomp($file[$n_line + 3]);
@matrix_line2 = split(/ +/, $file[$n_line + 3]);
chomp($file[$n_line + 4]);
@matrix_line3 = split(/ +/, $file[$n_line + 4]);
#print "@matrix_line1\n @matrix_line2\n @matrix_line3\n";
$pressure_error=($matrix_line1[4]+$matrix_line2[5]+$matrix_line3[6])/3;
#print "$pressure_error\n";
open result1, ">>../pressure_error.txt";
print result1 "$pressure_error\n";
close result1;
}
}