Use gsub
which does global substitution:
echo This++++this+++is+not++done | awk '{gsub(/\++/," ");}1'
sub
function replaces only 1st match, to replace all matches use gsub
.
The 1
at the end tells AWK to print out the line after it's been gsub
ed on. You can avoid it by explicitly adding a print statement to the same action as the gsub
, e.g. {gsub(/\++/," "); print;}
– Andrey Kaipov
CommentedOct 22, 2019 at 18:14
來源:https://stackoverflow.com/questions/14432209/substitute-a-regex-pattern-using-awk#14432241