Skip to content
Advertisement

Substitute a regex pattern using awk

I am trying to write a regex expression to replace one or more ‘+’ symbols present in a file with a space. I tried the following:

JavaScript

Expected:

JavaScript

Any ideas why this did not work?

Advertisement

Answer

Use gsub which does global substitution:

JavaScript

sub function replaces only 1st match, to replace all matches use gsub.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement