Results 1 to 3 of 3
Dear awk/bash guru,
Here is the file which we would like to obtain the TIME(ps) vs DV/DL information and calculate the cumulative DV/DL.
Here is output "${pre0}_prod_v0_l${X}_${A}.out".
When X=1; ${A}=1~10
...
Enjoy an ad free experience by logging in. Not a member yet? Register.

 07102013 #1
 Join Date
 Aug 2012
 Posts
 24
awk cumulative average/include wilde card
Here is the file which we would like to obtain the TIME(ps) vs DV/DL information and calculate the cumulative DV/DL.
Here is output "${pre0}_prod_v0_l${X}_${A}.out".
When X=1; ${A}=1~10
When X=2; ${A}=1~10
...
When X=10; ${A}=1~10
Code:NSTEP = 250 TIME(PS) = 50.250 TEMP(K) = 295.76 PRESS = 215.7 Etot = 7764.8430 EKtot = 3002.7461 EPtot = 10767.5890 BOND = 2122.1691 ANGLE = 13.8020 DIHED = 4.9113 14 NB = 9.7072 14 EEL = 21.5693 VDWAALS = 2214.9972 EELEC = 15154.7452 EHBOND = 0.0000 RESTRAINT = 0.0000 DV/DL = 0.5972 EKCMT = 987.1029 VIRIAL = 1142.1202 VOLUME = 33281.4023 Density = 1.0260 Ewald error estimate: 0.7836E04  NSTEP = 500 TIME(PS) = 50.500 TEMP(K) = 297.03 PRESS = 199.5 Etot = 7714.8112 EKtot = 3015.5875 EPtot = 10730.3986 BOND = 2184.8452 ANGLE = 16.0653 DIHED = 4.4046 14 NB = 9.5927 14 EEL = 20.3086 VDWAALS = 2284.2392 EELEC = 15249.8542 EHBOND = 0.0000 RESTRAINT = 0.0000 DV/DL = 0.7104 EKCMT = 977.6539 VIRIAL = 834.2227 VOLUME = 33298.0519 Density = 1.0255 Ewald error estimate: 0.4997E04 
Code:TIME DV/DL cumulative_DV/DL 50.250 0.5972 0.5972 50.500 0.7104 0.6538 ... ... .... *note: 0.6538=(0.59720.7104)/2
Code:awk '$1 ~ /^NSTEP*/ { printf("%14.3f",$6)} $1 ~ /^DV/DL/ { printf("%14.3f\n",$3)}'
The next question is code simplification:
for X in 1
There are ${pre0}_prod_v0_l${X}_${A}.out ; A=1~10
We want to process cumulative average of A=1, A=1~2, A=1~3, A=1~4,...A=1~10, so here is our code. If it's not too much asking, we wonder if any guru could simplify the code?
Code:for ((X=1; X<=1; X++)) do for ((A=1; A<=10; A++)) do # get DV/DL over time awk '$1 ~ /^NSTEP*/ { printf("%14.3f",$6)} $1 ~ /^DV/DL/ { printf("%14.3f\n",$3)}' ${pre0}_prod_v0_l${X}_${A}.out > awk_dvdl_${pre0}_v0_l${X}_${A}.dat # The last three "dv/dl" of each file are useless so we have to remove them. head n 3 awk_dvdl_${pre0}_v0_l${X}_${A}.dat > awk_dvdl_${pre0}_v0_l${X}_${A}_remove_3.dat done # Here we have to process the file like this: # cat awk_dvdl_${pre0}_v0_l${X}_1_remove_3.dat > awk_dvdl_${pre0}_v0_l${X}_1.dat # cat awk_dvdl_${pre0}_v0_l${X}_1_remove_3.dat awk_dvdl_${pre0}_v0_l${X}_2_remove_3.dat > awk_dvdl_${pre0}_v0_l${X}_2.dat # cat awk_dvdl_${pre0}_v0_l${X}_1_remove_3.dat awk_dvdl_${pre0}_v0_l${X}_2_remove_3.dat awk_dvdl_${pre0}_v0_l${X}_3_remove_3.dat> awk_dvdl_${pre0}_v0_l${X}_3.dat # etc... #make variables clean var1="" var2="" var3="" for ((A=1; A<=10; A++)) do var1="cat" var2="$var2 awk_dvdl_${pre0}_v0_l${X}_${A}_remove_3.dat" var3="awk_dvdl_${pre0}_v0_l${X}_${A}.dat" echo "$var1 $var2 >> $var3" done > awk_dvdl_v0_total.sh chmod 700 awk_dvdl_v0_total.sh sh awk_dvdl_v0_total.sh for ((A=1; A<=10; A++)) do # calculate cumulative average awk '{printf("%14.3f",$1)} {printf("%14.3f",$2)}{DVDL+=$2} {printf("%14.3f\n",DVDL/NR)}' awk_dvdl_${pre0}_v0_l${X}_${A}.dat > awk_dvdl_${pre0}_v0_l${X}_${A}_final.dat done done
 07102013 #2
 07132013 #3
 Join Date
 Aug 2012
 Posts
 24
Thanks mrbruno! It works perfectly! Henry