Replace a block of numbers in sed

Solution 1:

You don't need the +. Just use the following:

echo "fdsafdsa 32432 dsafdas" | sed 's/[0-9]/#/g'

[0-9] will already match all digits, and replace every single one with #.


Since + is extended syntax, you could also do:

echo "fdsafdsa 32432 dsafdas" | sed -E 's/[0-9]+/#/g'

to replace the whole block of digits with one #.