To replace from one to several digits, use the
+ quantifier (or its lazy variant
+?) combined with
[0-9] (because sed doesn't support
\d and
[[:digit:]] is unnecessarily verbose).
+ means "as many as possible, at least one"
+? means "at least one, as many as required"
Contrasted with
* which means "as many as possible, none required", and
*? which means "as few as possible".
The difference between greedy and lazy quantifiers can be subtle - in your example it doesn't matter which is used, but there are other situations where it does matter, so it's a useful thing to keep in mind.
Note that sed needs extended mode (-E) for all the above to work except *
So, to handle lines starting with optional spaces, then at least one digit, then a space:
Code:
sed -E 's/^ *[0-9]+ //'
One final note, the above uses literal space characters. Both
\s and the long-winded
[[:space:]] match five additional whitespace characters other than space, so for clarity should be avoided when only looking for spaces.