我有这个awk命令,我需要输入一个日期变量。我确定我在某处遗漏了一些语法。任何专家都可以帮助我吗?基本上,我需要根据脚本的运行时间来改变日期。
date=$(date --date="1 month ago" +"%d-%b-%Y")
wget -qO - http://*********/users.csv > users
awk 'NR==1 {print "Primary Comments,Customer Account Number,Transaction Date,Service Description,Quantity,Unit,Price,Service Category,PI\x27sName,Purchaser\x27s Last Name,Short Contributing Center Name,Resource Name,Line Item Assistant,Line Item Comments"}
FNR==NR {S[$1]=$2; P[$1]=$3; next}
$1 in S {print "Bruker 500 NMR",P[$1],date,"500 MHz",$2/60,"Hour","5","500 MHz",S[$1],$1,"","501 NMR","","" }
' FS="," OFS="," OFMT="%.2f" $date users FS=" " wtmp > billing-$inst-$date.csv
答案 0 :(得分:5)
使用-v
选项。
awk -v date="$date" ....
但是GNU awk(gawk
)有自己的时间函数,这里记录了这些函数:http://www.gnu.org/software/gawk/manual/html_node/Time-Functions.html