这里我输入了 $11 作为字符串,并且可以正常工作。
gawk 'FS=\",\" {match($6,/([^\/])\/([^\/])\/([^\/]+)/,a); $11=sprintf(\"%d
%02d -%d 0 0 0\",a[3],a[1],1);$6=sprintf(\"%d-%02d-
%02d\",a[3],a[1],a[2]);$6=strftime(\"%Y-%m-%d %H:%M:%S\",mktime(\"2017 08
-3 0 0 0\")); print $1,$2,$3,$4,$5,$6,$7,$8,$9,$11,\"".date("Y-m-d
H:i:s")."\"}' OFS=',' ./stock_File.csv > ./stock_File_DEMO.csv
但是当我尝试这个
gawk 'FS=\",\" {match($6,/([^\/])\/([^\/])\/([^\/]+)/,a);
$11=sprintf(\"%d %02d -%d 0 0 0\",a[3],a[1],1);$6=sprintf(\"%d-%02d-
%02d\",a[3],a[1],a[2]);$6=strftime(\"%Y-%m-%d %H:%M:%S\",mktime($11));
print $1,$2,$3,$4,$5,$6,$7,$8,$9,$11,\"".date("Y-m-d
H:i:s")."\"}' OFS=',' ./stock_File.csv > ./stock_File_DEMO.csv
我在 SUSE 中遇到此错误,但在 UBUNTO 或 MAC OSX 中没有遇到此错误 El Caption:
fatal: strftime: second argument less than 0 or too big for time_t
请注意,这$11=sprintf(\"%d %02d -%d 0 0 0\",a[3],a[1],1)
只是一个演示,因为 1 在实际脚本中是一个 shell 变量,整个脚本都是通过 exec 在 php 中完成的。我已将问题简化为核心问题。
我的输入文件如下所示:
"MERCK KGAA O.N.","MRK.DE",92.59,92.33,"-0.28%","8/7/2017",N/A,92.21,93.01
"MUENCH.RUECKVERS.VNA O.N.","MUV2.DE",186.15,186.30,"+0.08%","8/7/2017",N/A,185.80,186.65
"PROSIEBENSAT.1 NA O.N.","PSM.DE",34.240,34.105,"-0.394%","8/7/2017",5.260,34.015,34.305
"RWE AG ST O.N.","RWE.DE",18.495,18.505,"+0.054%","8/7/2017",N/A,18.395,18.545
"SAP SE O.N.","SAP.DE",91.44,91.06,"-0.42%","8/7/2017",N/A,90.99,91.51
"SIEMENS AG NA","SIE.DE",111.55,111.60,"+0.04%","8/7/2017",N/A,111.45,112.25
"THYSSENKRUPP AG O.N.","TKA.DE",25.41,25.59,"+0.73%","8/7/2017",0.54,25.48,25.73
"VOLKSWAGEN AG ST O.N.","VOW.DE",131.95,131.35,"-0.45%","8/7/2017",N/A,131.00,131.95
"VONOVIA SE NA O.N.","VNA.DE",35.900,35.765,"-0.376%","8/7/2017",N/A,35.685,36.000
有什么想法或帮助吗?谢谢