Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

how is sed generating .2.

how is sed generating .2.

how is sed generating .2.

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/



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}/)
NewName=$(echo ${NAME} | sed -e s/log\.[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/\.${EXTENSION}/)

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}/)
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}/)

RE: how is sed generating .2.

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...


# echo log.2017032222PDT | sed -e s/[.][0-9]*..T$/\.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}.

RE: how is sed generating .2.

Ahh ok totally saw my errors you pointed out. This works like a charm! thanks much!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close