3

I am an OpenBSD user and I am writing an awk script which automatically generates TeX course calendars for all courses that I teach. To obtain actual calendar out of the system I use Unix cal command. The problem is that the output of the cal command uses spaces as a delimiters which creates all sorts of problems when I apply my nawk script to it. I looked the source code for cal and seems that nothing short of hacking the source code will force cal command to use delimiter other than the space. What would be the simplest way to get calendar to look like this

        June 2012
Su, Mo, Tu, We, Th, Fr, Sa
  ,   ,   ,   ,   ,  1,  2
 3,  4,  5,  6,  7,  8,  9
10, 11, 12, 13, 14, 15, 16
17, 18, 19, 20, 21, 22, 23
24, 25, 26, 27, 28, 29, 30
2
  • Side note: did you check out the calendar tag over at TeX.SE?
    – Mat
    Commented May 29, 2012 at 7:36
  • @Mat I am not interested in any existing LaTeX classes and in particular TikZ "solutions" are irrelevant for me as I am PostScript bias. Commented May 29, 2012 at 22:57

1 Answer 1

5

You could use sed for that.

$ cal|sed -e '1n;s/\(..\)\(.\)/\1,\2/g'
      May 2012      
Su, Mo, Tu, We, Th, Fr, Sa
  ,   ,  1,  2,  3,  4,  5
 6,  7,  8,  9, 10, 11, 12
13, 14, 15, 16, 17, 18, 19
20, 21, 22, 23, 24, 25, 26
27, 28, 29, 30, 31

1n prints the first line and moves to the next. The replacement then takes the chars three by three and prints the first two followed by , then the third.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .