For a full list of BASHing data blog posts see the index page.     RSS

Second Tuesday of each month and a BASHing data century

My wife has a lunchtime meeting on the second Tuesday of each month, so naturally I thought about command-line ways to get a list of the meeting dates for a calendar year (with Priscilla's help; see below).

2020-03-16: Due to the COVID-19 emergency, those meetings have now been cancelled.

The simplest approach I came up with was to use the ncal calendar utility. By default, ncal prints the current month in the current year and highlights the current day, like this:


ncal puts Tuesdays on the 4th line of its output. The date of the second Tuesday is the third field in line 4, if I use AWK (which defaults to a sequence of spaces as field separator):


If I store the month field and year field in the first line in a variable, then append that variable to the second Tuesday's date with the default separator (a single space), I get a full date for the second Tuesday in the current month:


Last job is to loop through all the year's months. The month-specifying option for ncal is -m [number]:


for i in {1..12}; do ncal -m "$i" | awk 'NR==1 {moyr=$1" "$2} NR==4 {print $3,moyr}'; done

For a Python script to do this job, see this post from Luke Rawlins.

I started the BASHing data blog in May 2018 as a companion to A Data Cleaner's Cookbook. Both of these online resources were aimed at command-line data workers, but the blog was only meant to be an occasional dive into the details of Cookbook code.

Things didn't go according to plan. When 2019 arrived the blog had already become a weekly dip into a much wider range of data-related topics. This is the 100th BASHing data post and although the blog will continue into its second century, the posts may appear less often than once a week.

BASHing data will continue to be hand-coded in a text editor and will contain no JavaScript, ads, cookies, trackers, social media buttons or anything else that might contribute to the website obesity crisis. I hope you find at least some of the posts useful in your own data work!

For encouragement I'm grateful to our cat, Priscilla. She dozes on my belly while I lie face-up on the couch, trying to work through a processing problem in my head. Cats are known to have an affinity for coding, and Priscilla helps me to concentrate on the problem: Stop fidgeting. I'm an old cat and I need my sleep.


Last update: 2020-03-25
The blog posts on this website are licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License