gsub in awk

 

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 gsubed on. You can avoid it by explicitly adding a print statement to the same action as the gsub, e.g. {gsub(/\++/," "); print;} 

 CommentedOct 22, 2019 at 18:14

 

来源:https://stackoverflow.com/questions/14432209/substitute-a-regex-pattern-using-awk#14432241

 

posted @ 2024-11-19 18:19  profesor  阅读(7)  评论(0编辑  收藏  举报