Uses variables and regex in substitution in AWK?

Let's say I have an AWK script where a string variable is my_var

defined (and equal ;

- just in case this is important). Now I want to remove one or more occurrences my_var

from another line:

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

      

Obviously this doesn't work. But how do I build this command gsub

(or how do I avoid my_var

) to make this happen?

+3


source to share


1 answer


You can build a regex with a string:



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

      

+3


source







All Articles