Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how is sed generating .2.

Status
Not open for further replies.

grazinggoat

Programmer
Mar 12, 2008
41
0
0
US
I have files that are log.20170321PDT 8 numeric spaces and log.2017032307PDT 10 spaces
the script does a conversion to add seconds to the time stamp to keep them unique
when zipping but for some reason sed adds the extension below

I'm at a loss on where the .2. is being genrated by sed
any thoughts?

echo log.2017032222PDT | sed -e s/\.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]..T$/\.20170322225715PDT/

generates:

log.2.20170322225715PDT

i want the replacement to be log.20170322225715PDT for both 8 or 10 spaced files

if echo ${NAME} | egrep "log.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]..T" > /dev/null 2>&1 ; then
NewName=$(echo ${NAME} | sed -e s/log\.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]..T$/\.${EXTENSION}/)
else
NewName=$(echo ${NAME} | sed -e s/log\.[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/\.${EXTENSION}/)
fi


if echo ${NAME} | egrep "log.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]..T" > /dev/null 2>&1 ; then
NewName=$(echo ${NAME} | sed -e s/log\.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]..T$/\.${EXTENSION}/)
else
NewName=$(echo ${NAME} | sed -e s/log\.[0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/\.${EXTENSION}/)


 
That dot (\.) is matching ANY character, not a dot. And you have an incorrect number of numeric digits ([0-9]). So that dot is matching the first '2', not the dot. So it's not being matched the way you intended.

Try this...

Code:
# echo log.2017032222PDT | sed -e s/[.][0-9]*..T$/\.20170322225715PDT/
log.20170322225715PDT

The dot in brackets actually matches a dot. Then you match any number of numeric digits up to <anything><anything>T<end-of-line}.


 
Ahh ok totally saw my errors you pointed out. This works like a charm! thanks much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top