在AWK中編寫腳本 - 輸入數據 - 時間格式爲31.12.2012
。我想比較兩個日期 - 系統日期和這個日期。我認爲最好的方法是將這兩個日期轉換爲unix時間戳,進行演繹,然後與條件進行比較。日期只能以2012-12-31
格式轉換爲unix時間戳。爲了轉換成這種格式,我寫了SED表達式sed -n -e "s_\(..\)\(.\)\(..\)\(.\)\(....\)_\5-\3-\1_p"
。然後我們必須用命令date --utc --date "2012-12-31" +%s
來轉換這個表達式。但管道不想工作。在AWK中使用管道
在AWK我寫道:
#/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;
}
}
主線程是後12634588.謝謝!