Apologies if this is not a correct forum to ask, but I have a problem with awk (opensuse 11.1), which totally escapes my comprehension. In an awk program, I wanted to convert the time to Unix time (sec since 1970-1-1), and to check, I convert back. I use the date program piped into a variable.
The problem is that it works sometimes, but sometimes not and I do not understand why. I have made a small test program, which essentially consists of 3 lines, and I repeat these lines a number of times with different times.
The first 3 result are ok, but the 4th (and others following) are not. It appears that the results are only ok for times which haven’t been used before, but if the time is given for a second or next time, the result is wrong and the time printed is from a previous time (see for example at the last 6 results). It is the Unix time which incorrect (the first date pipe command), not the back conversion.
I have been looking for days, modifying and simplifying the code, until this test program was made. The program is below.
Any help or suggestion is welcome.
Charles
awk ’
BEGIN{
print
print “-------”
“date -d 10:15 +%s " | getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
"date -d 23:55 +%s “| getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
“date -d 00:00 +%s " | getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
“date -d 10:15 +%s " | getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
“date -d 21:37 +%s " | getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
“date -d 21:39 +%s " | getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
“date -d 15:15 +%s " | getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
“date -d 20:15 +%s " | getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
“date -d 21:15 +%s " | getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
“date -d 10:15 +%s " | getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
“date -d 15:15 +%s " | getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
“date -d 20:15 +%s " | getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
“date -d 21:15 +%s " | getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
“date -d 00:00 +%s " | getline abs_time
print abs_time
“date -d @” abs_time " +%F” "%T " | getline a; print a
}
END{
}’ < /dev/null