Jeremy White
Jeremy White

Reputation: 2829

Awk strftime on Mac OS X

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?

Upvotes: 14

Views: 13462

Answers (3)

5argon
5argon

Reputation: 3863

Use Homebrew and then just run brew install gawk

Upvotes: 12

ghostdog74
ghostdog74

Reputation: 342433

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

Upvotes: 19

jamessan
jamessan

Reputation: 42677

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.

Upvotes: 4

Related Questions