Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
    
Side note: did you check out the calendar tag over at TeX.SE? –  Mat May 29 '12 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. –  Predrag Punosevac May 29 '12 at 22:57

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
    
Exactly what I was looking for! Thanks!!! –  Predrag Punosevac May 29 '12 at 14:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.