The system
command in awk, as in C, returns the exit status of a command, and not the output of said command. As others have suggested, your best bet is using getline
from a pipe
I ran into a similar problem a while back and rolled my own exec
function, here it is:
# get the output of a command
function exec(cmd, data) {
while ((cmd | getline data) > 0) printf("%s", data);
close(cmd);
}
Then using the function defined above, you should do something like this:
epoch = exec("date +%s -d \"<ISO DATE>\"")
where <ISO DATE>
is an ISO conformant date/timestamp.
Example:
# helper.awk is where `exec` is defined
awk '@include "helper.awk"; BEGIN
{
epoch = exec("gdate -d \"2014-02-14T12:30\" +%s");
print epoch
}'
# 1392406200