Sed seems to replace only the last occurrence in global string substitution
问题 I use this command, but it's not working ad intended: echo "0+223+141+800+450+1*(106+400)+1*(1822+500)+1*(183+400)" | sed 's/\*\(.*\)+/*\1suma/g' This is the expected output: 0+223+141+800+450+1*(106suma400)+1*(1822suma500)+1*(183suma400) but this is what I get: 0+223+141+800+450+1*(106+400)+1*(1822+500)+1*(183suma400) It looks like only the last occurrence is being replaced, despite the use of g . 回答1: Try the following: echo "0+223+141+800+450+1*(106+400)+1*(1822+500)+1*(183+400)" | sed 's/