Using strftime function in mawk

Ariel.T picture Ariel.T · Sep 10, 2010 · Viewed 16.1k times · Source

I'm trying to create AWK script that will filter the input file according to some pattern, and use the strftime() function for some calculations.

($2 ~ /^[HB]/ && $2 ~ /n$/){
        print strftime("%Y")
}

The interpreter in use is mawk. When triggering this script using this command:

awk -f script3 inputFile

I'm getting the error: "function strftime never defined"

Answer

Kamran picture Kamran · Sep 12, 2011

Installing GAWK will get you the function strftime back that you are missing natively in awk.

With Ubuntu 11.10 or simiar distribution you would issue following command to get the GAWK

sudo apt-get install gawk

You can also use it in gawk however you don't have to and can simply go ahead with your original awk script.