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*

6
  • How do you want to compare them? Put them in date order, or after a particular date or..? As Jeff shows below, you can change the date commands output format. gnu.org/software/coreutils/manual/html_node/… Commented Jan 18, 2018 at 0:58
  • I have an array that will store the dates and a couple of loops will sort them but the issue is that in order for me to sort them I need to compare them and I need for them to be in the format mentioned in the question. Commented Jan 18, 2018 at 1:05
  • I think it would be sed -E ‘s/([[:digit:]]{4}):([[:digit:]]{2}):([[:digit:]]{2})(.*)/\1-\2-\3\4/‘ maybe. Capture year, month, day, and rest, and reprint. Commented Jan 18, 2018 at 1:14
  • 1
    With GNU sed you could replace all of the colons - then swap back from the third onward e.g. 's/:/-/g; s/-/:/3g' Commented Jan 18, 2018 at 1:20
  • 2
    you should fix the problem at the source if you can - i.e. fix whatever it is that's producing dates in that bogus format. Nobody uses : as separator between year, month, day. Commented Jan 18, 2018 at 2:28