Hi how can I use gsub to replace a word which has parentheses.Here I want to replace ABC(T) with ABC/Gawk ' {gsub(ABC\(T\),ABC/G)}; Print $0' $FILENAME > tmp.tmp && mv tmp.tmp $FILENAME
using gsub in awk to replace a word with parentheses
text processing;awk;regular expression;string
You could simplify the whole thing if you use the // format for gsub:$ echo ABC(T) | awk '{gsub(/ABC\(T\)/,ABC/G)}; print $0'ABC/GThen, you could simplify further by using print with no arguments (which is the same as print $0) or the 1 shorthand for printing (the default awk action for expressions that evaluate to true, such as 1; is to print the current line):$ echo ABC(T) | awk '{gsub(/ABC\(T\)/,ABC/G)}1'ABC/GPersonally, however, I wouldn't use awk for this, the syntax is shorter and cleaner with other tools:$ echo ABC(T) | sed 's|ABC(T)|ABC/G|'ABC/G$ echo ABC(T) | perl -pe 's|ABC\(T\)|ABC/G|'ABC/G