Artificial intelligent assistant

Remove leading string in bash I have a string like `rev00000010` and I only want the last number, 10 in this case. I have tried this: TEST='rev00000010' echo "$TEST" | sed '/^[[:alpha:]][0]*/d' echo "$TEST" | sed '/^rev[0]*/d' both return nothing, although the regex seems to be correct (tried with regexr)

The commands you passed to `sed` mean: _if a line matches the regex, delete it_. That's not what you want.


echo "$TEST" | sed 's/rev0*//'


This means: _on each line, remove rev followed by any number of zeroes._

Also, you don't need `sed` for such a simple thing. Just use bash and its parameter expansion:


shopt -s extglob # Turn on extended globbing.
echo "${TEST##rev*(0)}" # Remove everything from the beginning up to `rev`
# followed by the maximal number of zeroes.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 6288d9d2d2162da6e5a28bed52450662