I'd like to grab the digits in a string like so :
"sample_2341-43-11.txt" to 2341-43-11
And so I tried the following command:
echo "sample_2341-43-11.txt" | sed -n -r 's|[0-9]{4}\-[0-9]{2}\-[0-9]{2}|\1|p'
I saw this answer, which is where I got the idea. Use sed to grab a string, but it doesn't work on my machine:
- it gives an error "illegal option
-r
". - it doesn't like the
\1
, either.
I'm using sed on MacOSX yosemite.
Is this the easiest way to extract that information from the file name?