A S
A S

Reputation: 1235

Usings variables AND regex within substitute routine in AWK?

Let's say I have an AWK script, where the string variable my_var is defined (and equals to ; -- just in case this matters). Now, I want to delete one or more occurrences of my_var from another string:

gsub(/my_var+/, "", another_string)

Obviously, this doesn't work. But how should I construct this gsub command (or, how should I escape my_var) to make it happen?

Upvotes: 3

Views: 73

Answers (1)

anubhava
anubhava

Reputation: 785266

You can construct regex using string:

gsub(my_var "+", "", another_string)

Upvotes: 3

Related Questions