tags:

views:

241

answers:

2

The following command on my Mac (10.6) gives me an undefined function error:

$ awk 'BEGIN{now=strftime("%D", systime()); print now}'
awk: calling undefined function strftime
 source line number 1

On a Red Hat system, I get the expected result:

$ awk 'BEGIN{now=strftime("%D", systime()); print now}'
12/01/09

What's the deal here?

+1  A: 

You're relying on an extension to awk that's present in whichever variant (gawk, mawk, nawk, etc.) your Red Hat system happens to be using. See the Standard Unix Specification's awk description for what you can expect as a baseline for awk.

jamessan
+1  A: 

strftime is a GNU gawk extension. If you want to use strftime, download GNU gawk and install on your Mac. Otherwise, there are other tools like Perl/Python you can use. Check if you have them on your Mac

I installed gawk, mawk and nawk using MacPorts, but I still get the same error.
Jeremy White
how did you invoke it? are they in the correct PATH?
sudo port install gawkI can confirm that gawk is in the correct PATH, but can't find any reference to strftime
Jeremy White
Correct syntax after installing gawk wasgawk 'BEGIN{now=strftime("%D", systime()); print now}'
Jeremy White
My text book was using awk rather than gawk, so I was confused as to why it still wasn't working for me.
Jeremy White