I have the string:
20120113083000Z
and I want to convert it to:
2012 01 13 08 30 00 Z
ready for the mktime command to convert it to a date stamp.
I have at present:
echo '20120113083000Z' |
awk '{print mktime(gensub(/(....)(..)(..)(..)(..)(..)(.)/,"\\1 \\2 \\3 \\4 \\5 \\6 \\7",1g,$1))}'
1326439800
I know I could use sed or bash to convert it, but I would like to keep it inside an awk process.
Is there a better (shorter or more elegant) way?
N.B. I would like to make it as generic as possible (gensub gawk only(?)).
1 Answer