MotorCycleDude
Technical User
I have a ‘relatively’ simple awk script that changes ‘columns’ (delimited by whitespaces) in an ascii text file. It is sound and works until you introduce a special character like “(“ or “[“. It then results in the error message below and doesn’t make the change. I’ve Googled and Googled and Googled, but no solution. Will anyone help? TIA , Matt
Here’s what I get if one of the columns contains “[“ or “(“
change_by_col abc -c 3 -t BARNEY
awk: /home/matt/Software/Scripts/change_by_col:232: (FILENAME=abc FNR=3) fatal: invalid regexp: Unmatched [, [^, [:, [., or [=: /[BUBBA/
Here’s the text file:
apples peaches BUBBA pie
apples peaches BUBBA pie
apples peaches [BUBBA pie
apples peaches BUBBA pie
apples peaches BUBBA pie
Here’s the line that errors out (232)
sub($col_to_chg,to);
(btw, “to” above is what’s assigned from the “-t” argument.
Here’s what I get if one of the columns contains “[“ or “(“
change_by_col abc -c 3 -t BARNEY
awk: /home/matt/Software/Scripts/change_by_col:232: (FILENAME=abc FNR=3) fatal: invalid regexp: Unmatched [, [^, [:, [., or [=: /[BUBBA/
Here’s the text file:
apples peaches BUBBA pie
apples peaches BUBBA pie
apples peaches [BUBBA pie
apples peaches BUBBA pie
apples peaches BUBBA pie
Here’s the line that errors out (232)
sub($col_to_chg,to);
(btw, “to” above is what’s assigned from the “-t” argument.