How to append column to existing file in awk? -
i have file named bt.b.1.log looks this:
. . . time in seconds = 260.37 . . . compiled procs = 1 . . . time in seconds = 260.04 . . . compiled procs = 1 . . . and on 40 records of time in seconds , compiled procs (dots represent useless lines). how add single column value of compiled procs (which 1) result of following 2 commands:
this prints average of time in seconds values (thanks dawg one)
awk -f= '/time in seconds/ {s+=$2; c++} end {print s/c}' bt.b.1.log > t1avg.dat
desired output:
260.20 1 this prints of ocurrences of time in seconds, there small problem it; printing blank line @ beginning of list.
awk 'begin { fs = "time in seconds =" } ; { printf $2 } {printf " "}' bt.b.1.log > t1.dat
desired output:
260.37 1 260.04 . . . in both cases need value of compiled procs appear once, preferrably in first line, , no use of intermediate files. managed far prints values of time in seconds compiled procs column appearing in every line , strange identation:
awk '/seconds/ {printf $5} {printf " "} /procs/ {print $4}' bt.b.1.log > t1.dat please help!
update
contents of file bt.b.1.log:
-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/- start in 16:40:51--25/12/2014 nas parallel benchmarks 3.3 -- bt benchmark no input file inputbt.data. using compiled defaults size: 102x 102x 102 iterations: 200 dt: 0.0003000 number of active processes: 1 time step 1 time step 20 time step 40 time step 60 time step 80 time step 100 time step 120 time step 140 time step 160 time step 180 time step 200 verification being performed class b accuracy setting epsilon = 0.1000000000000e-07 comparison of rms-norms of residual 1 0.1423359722929e+04 0.1423359722929e+04 0.7507984505732e-14 2 0.9933052259015e+02 0.9933052259015e+02 0.3147459568137e-14 3 0.3564602564454e+03 0.3564602564454e+03 0.4783990739472e-14 4 0.3248544795908e+03 0.3248544795908e+03 0.2309751522921e-13 5 0.3270754125466e+04 0.3270754125466e+04 0.8481098651866e-14 comparison of rms-norms of solution error 1 0.5296984714094e+02 0.5296984714094e+02 0.2682819657265e-15 2 0.4463289611567e+01 0.4463289611567e+01 0.1989963674771e-15 3 0.1312257334221e+02 0.1312257334221e+02 0.4060995034457e-15 4 0.1200692532356e+02 0.1200692532356e+02 0.2958887128106e-15 5 0.1245957615104e+03 0.1245957615104e+03 0.2281113665977e-15 verification successful bt benchmark completed. class = b size = 102x 102x 102 iterations = 200 time in seconds = 260.37 total processes = 1 compiled procs = 1 mop/s total = 2696.83 mop/s/process = 2696.83 operation type = floating point verification = successful version = 3.3 compile date = 25 dec 2014 compile options: mpif77 = mpif77 flink = $(mpif77) fmpi_lib = -l/usr/lib/openmpi/lib -lmpi -lopen-rte -lo... fmpi_inc = -i/usr/lib/openmpi/include -i/usr/lib/openm... fflags = -o flinkflags = -o rand = (none) please send results of run to: npb development team internet: npb@nas.nasa.gov if email not available, send to: ms t27a-1 nasa ames research center moffett field, ca 94035-1000 fax: 650-604-3957 finish in 16:45:14--25/12/2014 -/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/- -/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/- start in 16:58:50--25/12/2014 nas parallel benchmarks 3.3 -- bt benchmark no input file inputbt.data. using compiled defaults size: 102x 102x 102 iterations: 200 dt: 0.0003000 number of active processes: 1 time step 1 time step 20 time step 40 time step 60 time step 80 time step 100 time step 120 time step 140 time step 160 time step 180 time step 200 verification being performed class b accuracy setting epsilon = 0.1000000000000e-07 comparison of rms-norms of residual 1 0.1423359722929e+04 0.1423359722929e+04 0.7507984505732e-14 2 0.9933052259015e+02 0.9933052259015e+02 0.3147459568137e-14 3 0.3564602564454e+03 0.3564602564454e+03 0.4783990739472e-14 4 0.3248544795908e+03 0.3248544795908e+03 0.2309751522921e-13 5 0.3270754125466e+04 0.3270754125466e+04 0.8481098651866e-14 comparison of rms-norms of solution error 1 0.5296984714094e+02 0.5296984714094e+02 0.2682819657265e-15 2 0.4463289611567e+01 0.4463289611567e+01 0.1989963674771e-15 3 0.1312257334221e+02 0.1312257334221e+02 0.4060995034457e-15 4 0.1200692532356e+02 0.1200692532356e+02 0.2958887128106e-15 5 0.1245957615104e+03 0.1245957615104e+03 0.2281113665977e-15 verification successful bt benchmark completed. class = b size = 102x 102x 102 iterations = 200 time in seconds = 260.04 total processes = 1 compiled procs = 1 mop/s total = 2700.25 mop/s/process = 2700.25 operation type = floating point verification = successful version = 3.3 compile date = 25 dec 2014 compile options: mpif77 = mpif77 flink = $(mpif77) fmpi_lib = -l/usr/lib/openmpi/lib -lmpi -lopen-rte -lo... fmpi_inc = -i/usr/lib/openmpi/include -i/usr/lib/openm... fflags = -o flinkflags = -o rand = (none) please send results of run to: npb development team internet: npb@nas.nasa.gov if email not available, send to: ms t27a-1 nasa ames research center moffett field, ca 94035-1000 fax: 650-604-3957 finish in 17:03:12--25/12/2014 -/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/- there 40 entries in log, i've provided 2 abbreviation purposes.
to fix first issue, replace:
awk -f= '/time in seconds/ {s+=$2; c++} end {print s/c}' bt.b.1.log > t1avg.dat with:
awk 'begin { fs = "[ \t]*=[ \t]*" } /time in seconds/ { s += $2; c++ } /compiled procs/ { if (! cp) cp = $2 } end { print s/c, cp }' bt.b.1.log >t1avg.dat a potential minor issue 260.205 1 might output question not address weakness of given script. rounding printf "%.2f %s\n", s/c, cp gives 260.21 1 though. truncate digit, use printf "%.2f %s\n", int (s/c * 100) / 100, cp.
to fix second issue, replace:
awk 'begin { fs = "time in seconds =" } ; { printf $2 } {printf " "}' bt.b.1.log > t1.dat with:
awk 'begin { fs = "[ \t]*[=][ \t]" } /time in seconds/ { printf "%s", $2 } /compiled procs/ { if (cp) { printf "\n" } else { cp = $2; printf " %s\n", $2 } }' bt.b.1.log > t1.dat btw, "strange indentation" result of failing output newline when using printf , failing filter unwanted input lines processing.
Comments
Post a Comment