Sed substitution not doing what I want and think it should do

Posted by nategoose on Stack Overflow See other posts from Stack Overflow or by nategoose
Published on 2010-04-01T16:26:02Z Indexed on 2010/04/01 16:53 UTC
Read the original article Hit count: 195

Filed under:
|
|

I have am trying to use sed to get some info that is encoded within the path of a file which is passed as a parameter to my script (Bourne sh, if it matters). From this example path, I'd like the result to be 8

PATH=/foo/bar/baz/1-1.8/sing/song

I first got the regex close by using sed as grep:

echo $PATH | sed -n -e  "/^.*\/1-1\.\([0-9][0-9]*\).*/p"

This properly recognized the string, so I edited it to make a substitution out of it:

echo $PATH | sed -n -e "s/^.*\/1-1\.\([0-9][0-9]*\).*/\1/"

But this doesn't produce any output. I know I'm just not seeing something simple, but would really appreciate any ideas about what I'm doing wrong or about other ways to debug sed regular expressions.

© Stack Overflow or respective owner

Related posts about sed

Related posts about regular-expression