I have the following string
str="toto1 toto2 toto3 toto4 toto2 toto5"
the toto2
occurs twice in the string. How can I remove all toto2
occurrences from the string?
I tried this:
echo ${str/toto2/}
But this will remove only the first occurrence of toto2
.
toto1 toto3 toto4 toto2 toto5 # output
How can I remove all toto2
occurrences from the string?
Found it. The solution is:
echo "${str//toto2/}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With