[PLUG] gawk: escaping parentheses in pattern string

Rich Shepard rshepard at appl-ecosys.com
Sat Mar 28 21:33:47 UTC 2020


The second field in a file is a string (but not demarked as such with
quotes) and I want to replace it with a number. The gawk pattern match for
40 of these strings work, but when $2 == B(W) gawk doesn't like it.

/$2 ~ B(W)/ { $2=11; print $0 }

I tried escaping the parentheses with backslashes \( and \) and quoting the
string "B(W)" but both result in a syntax error. I've not found the proper
way to replace B(W) with 11 and need a clue.

Rich



More information about the PLUG mailing list