bash - Override variables in awk scripts in command line/mother scripts -
if have awk script (average.sh) , use process lot of inputfiles
awk -f\" 'begin{print} last != $4""$8 && last{ print line,exp(c/d) c=d=0} { # block process each line of infile c += log($(nf-1)+0) d++ $(nf-1)="" line=$0 last=$4""$8} end{ # block triggers after complete file read # print last average cannot trigger during # previous block print line,exp(c/d)}' ${var2:=infile}
now if do
export var2="infile4" | sh average.sh
the "average.sh" still process "infile" instead of "infile4".
following best answers in override variable in bash script command line , try
var2=infile4 ./geometric_average_real
this give error of "var2=infile: command not found."
our final goal write loops
for (x=1; x<=3; x++) sh average.sh infile${x} done
so loop shall process
sh average.sh infile1 sh average.sh infile2 sh average.sh infile3
thanks comments!
if average.sh script working single infile, call script list of files process:
#!/bin/bash test -n "$1" || { echo "error, insufficient input"; exit 1; } avgscript="/path/to/average.sh" test -x "$avgscript" || { echo "error: required script `$avgscript` not found or not executable"; exit 1; } in "$@"; avgscript "$i" done
save file runavg.sh
, call runavg.sh file1 file2 file2
Comments
Post a Comment