Writing script in AWK – input data – time in format 31.12.2012. I want to compare 2 dates – system date and this date. I think the best way is to convert both dates into unix timestamp, make deduction and then compare with conditional. Date can be converted into unix timestamp only with this format 2012-12-31 . To convert into this format I write SED expression sed -n -e "s_\(..\)\(.\)\(..\)\(.\)\(....\)_\5-\3-\1_p". And then we must convert this expression with command date --utc --date "2012-12-31" +%s. But pipes doesnt want to work.
In the AWK i wrote:
#/usr/bin/awk -f
BEGIN {
FS=",";
}
{
split($3, account, "/");
gsub(/ $/, "", account[1]);
split($4, products, "\\\\n");
split($5, supports, "\\\\n");
for (i in products) {
gsub("\"", "", products[i]);
gsub("\"", "", supports[i]);
split(supports[i], timesupport, "\ > ");
"date +%s" | getline dateVal;
print timesupport[1] | sed -n -e "s_\(..\)\(.\)\(..\)\(.\)\(....\)_\5-\3-\1_p" | getline timeVal1 | date --utc --date "timeVal1" +%s | getline timeVal;
x=dateVal - timeVal;
if (supports[i] !~ /n\\\\a*/ && supports[i] !~ /n\/a*/ && $2 !~ /\NULL/)
print $1","$2","timesupport[1]","account[1]"\","products[i]"\","$6;
}
}
The main thread was in post 12634588. Thanks!
Why not use the builtin time functions:
To convert the string you mentioned to the same format, use
mktime:Output: