SED help, small problem

Hi,

I have this sed command to grep a date from a filename for a script we have.
I am awful with sed so I need help.
Sometimes it works fine but other times it does not, see below.

works

bash-3.00# echo /US/fwadmnyc05-ezone.us.db.com/nj34ex08k3y07/http_log.nj34ex08k3y07.2010.06.04.00.05.00.432.gz | sed -e 's#.*/##' -e 's#[^0-9][^0-9]*[.]\([0-9][0-9.][0-9.]*\)[.].*#\1#'
http_log.nj34ex08k3y07.2010.06.04.00.05.00.432.gz

Doesn't work, the 2009 is part of the filename:

bash-3.00# echo /US/fwadmnyc05-ezone.us.db.com/nj02ga03e2y39a/http_log.nj02ga03e2y39a.2009.11.16.01.01.03.274.gz|sed -e 's#.*/##' -e 's#[^0-9][^0-9]*[.]\([0-9][0-9.][0-9.]*\)[.].*#\1#' 
http_log.nj02ga03e2y392009.11.16.01.01.03.274

by the way there is obviously another | cut -d. -f3,4,5 after the above commands to just get the dates but the sed seems to be the issue.
I really do not understand why it sometimes work or sometimes does not as the filename format is the same...

The file format is always http_log.hostname.yyyy.mm.dd.some.info.blah.gz

Help please

If it's ok without sed, shell can do it too:

$> VAR='/US/fwadmnyc05-ezone.us.db.com/nj02ga03e2y39a/http_log.nj02ga03e2y39a.2009.11.16.01.01.03.274.gz'
$> echo ${VAR##*/}
$> http_log.nj02ga03e2y39a.2009.11.16.01.01.03.274.gz

With sed I would write it like this (back referencing):

sed 's#.*/\([^/]*\)#\1#g'
1 Like