#! /bin/bash
files=(*.txt)
for ((i=0; i<${#files[@]}; i++)) ; do
file="${files[$i]}"
awk -f f.awk "$file" > "${file}.mod"
done
f.awk is:
{
gsub(/\([^)]*\)/,"&; printf&")
print
}
input.txt:
x=7;
sqrt(x+5*4); sqrt(x*x);
i=3;
a=2+sqrt(8);
Running: awk -f f.awk input.txt gives:
x=7;
sqrt(x+5*4); printf(x+5*4); sqrt(x*x); printf(x*x);
i=3;
a=2+sqrt(8); printf(8);
This wont work for nested parenthesis, like sqrt(4+2*(x+y))
Running: awk -f f.awk input.txt>>output.txt writes it to output file
Pretty neat!
ReplyDelete