Discussion:
Reformat a list of datetimes
List Gnome listgnome@yahoo.com [sed-users]
2018-08-24 02:07:19 UTC
Permalink
Hello SED Users,

I have a file that has a list of datetimes like so:

Sun Nov 29 03:35:21 2015
Mon Dec 21 00:08:13 2015
Thu Feb 11 02:24:05 2016

I would like to re-format the datetimes like so:

Sun, 29 Nov 2015 03:35:21
Mon, 21 Dec 2015 00:08:13
Thu, 11 Feb 2016 02:24:05

Any suggestions or clues on how to do this in SED would be greatly appreciated.

Thanks,
Mark


[Non-text portions of this message have been removed]
Davide Brini dave_br@gmx.com [sed-users]
2018-09-03 14:08:05 UTC
Permalink
Post by List Gnome ***@yahoo.com [sed-users]
Hello SED Users,
Sun Nov 29 03:35:21 2015
Mon Dec 21 00:08:13 2015
Thu Feb 11 02:24:05 2016
Sun, 29 Nov 2015 03:35:21
Mon, 21 Dec 2015 00:08:13
Thu, 11 Feb 2016 02:24:05
Any suggestions or clues on how to do this in SED would be greatly appreciated.
Try the following:

sed 's/^\(...\) \(...\) \(..\) \(........\) \(....\)/\1, \3 \2 \5 \4/'

If your format is strictly as above it should work, otherwise you'll have to
refine the capturing groups a bit.
--
D.
dgoldman@ehdp.com [sed-users]
2018-09-04 01:15:52 UTC
Permalink
sed 's/^\(...\) \(...\) \(..\) \(........\) \(....\)/\1, \3 \2 \5 \4/' seems to work perfectly. Not so sure the yahoo groups software is working as well. The original post shows an 8/23/2018 timestamp on my computer, yet I believe it only sent out today, some ten days later. And I got three copies of the first response (from Davide). IMO, yahoo has been in a steady decline for many years, with software rot setting in, so I am not surprised. Anyway, it was an excellent post, and I hope the OP got his reply.

[Non-text portions of this message have been removed]

Thierry Blanc Thierry.Blanc@gmx.ch [sed-users]
2018-09-03 15:20:09 UTC
Permalink
if your dates might have some differences, you can use bash date command
to reformat the date.

date -d 'your-date-string'  '+%A ...'

(supposing you are on a *nx shell ...)
Post by List Gnome ***@yahoo.com [sed-users]
Hello SED Users,
Sun Nov 29 03:35:21 2015
Mon Dec 21 00:08:13 2015
Thu Feb 11 02:24:05 2016
Sun, 29 Nov 2015 03:35:21
Mon, 21 Dec 2015 00:08:13
Thu, 11 Feb 2016 02:24:05
Any suggestions or clues on how to do this in SED would be greatly appreciated.
Thanks,
Mark
[Non-text portions of this message have been removed]
------------------------------------
------------------------------------
Loading...