EmacsGolf: Changing Times to 24-Hour Notation

Here’s a problem I dealt with recently. We have a tab-delimited data file that has time as one of the fields. The times are in the U.S. 12-hour format with a trailing ā€˜aā€™ for AM or a ā€˜pā€™ or PM. We want the times to be in 24-hour format. The file looks like

# -*- Mode: text; indent-tabs-mode: t -*-
11/13/07        7:14a   232     74      70
11/13/07        8:05a   340     85      60
11/13/07        3:47p   927     79      66
11/14/07        7:58a   109     79      72
...

and we want it to look like

# -*- Mode: text; indent-tabs-mode: t -*-
11/13/07        07:14   232     74      70
11/13/07        08:05   340     85      60
11/13/07        15:47   927     79      66
11/14/07        07:58   109     79      72
...

Note that we want each time to contain exactly 5 characters (including the colon). None of the other fields should be changed.

The file is over 1,100 lines long so editing each line by hand is not feasible. How would you do this as efficiently as possible?

This entry was posted in General and tagged . Bookmark the permalink.