Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

2
  • 1
    At two seconds past noon, date will say 2013.06.14.12.00.02, and sed will output 2013.6.14.12..2.  Note that the 00 minutes field disappears completely, leaving two adjacent dots.  This is probably not what the user wants.  To do this correctly in GNU sed, use sed -E -e 's/^0?//' -e 's/\.0?/./g' (to delete zero or one 0).  Or, to do it portably in GNU or POSIX sed, use sed -e 's/^0//' -e 's/\.0/./g' (to delete one 0, or not; it’s OK if the substitution simply fails when there isn’t a leading 0).  … (Cont’d) Commented Sep 6, 2020 at 5:46
  • 1
    (Cont’d) … Note that a g option is useless on a substitute that’s anchored with ^ or $, since it cannot happen more than once. Commented Sep 6, 2020 at 5:46