Tay Ray Chuan home archive

scripting fun

Wed, 6 Oct 2010 23:34:34 +0800 | Filed under random

I needed to get a list of time slots of one hour each, from 900h to 1700h, for two days, 11th and 12th October. Unfortunately, Google Docs' spreadsheet wasn't clever enough to guess the pattern for Auto Fill to work.

Python came to mind:

>>> for day in (11,12):
...   for hour in range(9,18):
...     print "%s October - %s00" % (day, hour)
...
11 October - 900
11 October - 1000
11 October - 1100
11 October - 1200
11 October - 1300
11 October - 1400
11 October - 1500
11 October - 1600
11 October - 1700
12 October - 900
12 October - 1000
12 October - 1100
12 October - 1200
12 October - 1300
12 October - 1400
12 October - 1500
12 October - 1600
12 October - 1700

Then, I wanted to blast it out to a couple of people. Unfortunately, they weren't in my Contacts yet; I only had it in a spreadsheet, with a bunch of other info. So, I ran awk to select only the fields that I wanted:

$ cat file1.csv \
| awk 'BEGIN { FS="," } /^.+/ { print $1","$4; }' \
> file2.csv

(Note the regex wrapping print - this is to ensure only non-empty lines are taken.)

I wonder how "normal" people get on with tasks like this.

blog comments powered by Disqus