My inputs are commands followed by an unrestricted number of single-letter options, e.g. command -abc. Neither the command nor the options take any arguments. My goal is to remove certain options.
Removing options b and c as an example, I can achieve this like this:
$ cmd='command -abc'
$ pattern='(.*) -(.*)'
$ [[ $cmd =~ $pattern ]]
$ echo "${BASH_REMATCH[1]} -${BASH_REMATCH[2]//[cb]}"
command -a
However, this only works in bash. How can I solve this problem in a compatible way, e.g. using sed and grep ?