How to launch shell script from awk command -
i novice in ksh scripting , highly appreciate help. need parse data file looks this:
$ cat data.txt p1`/tmp/s1.ksh p2`/tmp/s2.ksh p3`/tmp/s3.ksh
here p1, p2, p3 parameter names, followed script names, calculate values parameters.
dummy scripts this:
$ cat s1.ksh !/bin/ksh echo "v1"
at end, need launch scripts , concatenate results parameter names , produce string looks this:
p1=v1 p2=v2 p3=v3
i try use awk this. understood, system() should launch scripts , print output resulting string.
$ awk -f\` '{ printf("%s ",$1); system("eval \"$(cat "$2")\"") }' /tmp/data.txt
but prints parameter names
p1 p2 p3
i checked if parsed data.txt correctly
$ awk -f\` '{ printf(" %s=",$1); printf("eval \"$(cat %s)\"", $2) }' /tmp/data.txt
the output is
p1=eval "$(cat /tmp/s1.ksh)" p2=eval "$(cat /tmp/s2.ksh)" p3=eval "$(cat /tmp/s3.ksh)"
so, expect system() should execute following command , concatenate output resulting string.
$ eval "$(cat /tmp/s2.ksh)"
could please me , explain why did not values v1, v2, v3 scripts. maybe there better way using awk solve task.
this might work:
echo $( while ifs=\\` read p sc $sc $p done < data.txt )
the shell loop splits lines in file , runs each script each param. echo $() run loop , collect output, , echo that, has effect of removing newlines.
Comments
Post a Comment