Code:
awk '
function replace_param(string,num,inq,inb,fval,out) {
fld=1
for(i=1;i<=length(string);i++) {
chr=substr(string,i,1)
if (!inq && chr == "(") inb++
if (!inq && inb && chr == ")") inb--
if (chr == "\"") inq=!inq
if (!inb && !inq && chr == ",") {
if(fld==num) out = out "$some_obj->" REPL[tolower(fval)]
out = out ","
fld++;
while(substr(string,++i,1)~"[[:blank:]\\n]") out = out substr(string,i,1);
}
if (fld==num && !inq && !inb) fval=fval substr(string,i,1);
if (fld!=num) out=out substr(string,i,1);
}
return out
}
BEGIN {
RS=";"
split ("one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen", TO, ",")
split ("0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f", FROM, ",")
for(i in FROM) REPL[FROM[i]]=TO[i]
}
$0 ~"[^[:alnum:]_]foo[^[:alnum:]_]*\\(" {
s=$0
while(match(s, "[^[:alnum:]_]foo[^[:alnum:]_]*\\(")) {
s=substr(s, 1, RSTART) "bar_new(" replace_param(substr(s,RSTART+RLENGTH), 2)
}
$0 = s
}
{ printf "%s", $0 (length>1? RS:"")}' infile