Here I have entered $11 as string and that works.

    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

But when I try this

    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

I get this Error in SUSE but not in UBUNTO or MAC OSX El Caption:

    fatal: strftime: second argument less than 0 or too big for time_t

Please not that $11=sprintf(\"%d %02d -%d 0 0 0\",a[3],a[1],1) is only a demo as the 1 is in the real script a shell variable and the whole sript is done in php by exec. I have reduced the problem to the core problem.

My input file looks like:

     "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

Any Ideas or help for me? THANKS

  • First thing to check is the versions of the various utilities. While Ubuntu includes rather up-to-date software (at least at publication time), some other distros tend to stick to much older versions.
    – xenoid
    Aug 7, 2017 at 10:48
  • Thanks, mind you telling me how I can check the version of SUSE gawk? Aug 7, 2017 at 13:59
  • On a hunch, gawk --version? Or ask the package manager what it installed.
    – xenoid
    Aug 7, 2017 at 22:18
  • On SUSE I have GNU Awk 4.1.0 API:1.0 and on Ubutnu GNU Akw 4.1.4 API: 1.1, how can I update my SUSE gawk? Thanks Aug 9, 2017 at 12:58


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.