9oubzg
Last Updated: August 20, 2016
·
45
· bitfragment

Sort a list of dates in U.S. expanded form (e.g., Tuesday, August 23, 2016)

Useful in writing a schedule containing selected weekdays (for a course syllabus, for example).

Generate lists of selected weekday dates (I use Research Maniacs Days by Year):

Tuesday, August 23, 2016
Tuesday, August 30, 2016
Tuesday, September 6, 2016
Tuesday, September 13, 2016
Tuesday, September 20, 2016
Tuesday, September 27, 2016
Tuesday, October 4, 2016
Tuesday, October 11, 2016
Tuesday, October 18, 2016
Thursday, August 25, 2016
Thursday, September 1, 2016
Thursday, September 8, 2016
Thursday, September 15, 2016
Thursday, September 22, 2016
Thursday, September 29, 2016
Thursday, October 6, 2016
Thursday, October 13, 2016
Thursday, October 20, 2016

Then sort with sort -k 2,2M -k 3,3n. This sorts using the second whitespace-delimited field (only) as a key, using the -M flag for string month name comparison, then uses the third whitespace-delimited field (only) as a key using the -n flag for numeric day.

Tuesday, August 23, 2016
Thursday, August 25, 2016
Tuesday, August 30, 2016
Thursday, September 1, 2016
Tuesday, September 6, 2016
Thursday, September 8, 2016
Tuesday, September 13, 2016
Thursday, September 15, 2016
Tuesday, September 20, 2016
Thursday, September 22, 2016
Tuesday, September 27, 2016
Thursday, September 29, 2016
Tuesday, October 4, 2016
Thursday, October 6, 2016
Tuesday, October 11, 2016
Thursday, October 13, 2016
Tuesday, October 18, 2016
Thursday, October 20, 2016

Using GNU coreutils sort 5.93 on x86-64 Apple Darwin 15.6.0.

Further reading: Sorting multiple keys with Unix sort

Say Thanks
Respond
Filed Under