I need to free a string from unwanted characters. In this example I want to filter all +
's and all -
's from b and write the result to c. So if b is +fdd-dfdf+
, c should be +-+
.
read b
c=$(echo $b | sed 's/[^(\+|\-)]//g')
But when i run the script, the console says:
sed: -e expression #1, char 15: Invalid range end
The reason is the \-
in my regular expression. How can I solve this problem and say, that I want to filter all -
's?
are you looking for this?
kent$ echo 'a + b + c - d - e'|sed 's/[^-+]//g'
++--
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