0

I have a series of javascript .js files where the original scripter used poor variable names such as 'a', 'b', etc.

I need to automate the substitution to more descriptive names, reliably only changing the single character variable name(s) and not erroneously modifying other variables which may include that letter.

I am thinking it could be done in awk with something like:

awk '{gsub(/a/, "new_name")};{print}' script.js

but need more sophistication in the regular expression /a/ so as not to change variable names erroneously.

1 Answers1

0

Well folks, I believe that I have a solution; at least it is close.

I have created a file named charac-sub.awk with:
{gsub(/\<a>/,"new_name1")
gsub(/\<b>/,"new_name2")
.
.
gsub(/\<e>/,"new_nameN")}; {print}


and when I run it from the command line:

awk -f charac-sub.awk script.js

It seems to do what I need.