computing
  • 2

Solved Adding Header & Trailer For Existing Csv File Through Batch

  • 2

I need to add Header as current UTC time format as “MM-DD-YYYYHH:MM:SS” & trailer as number record found on existing csv through Batch scripting. I need help for how to script this.

message edited by HI

Share

1 Answer

  1. Whert’s post gave me much to learn!
    Meantime, here’s a crappy hack (happy crack?) to fill the voids:

    @echo off
    set ap=P
    set d=%date:~4%
    set d=%d:/=-%
    :: note leading space in foll line at %time%, to dodge octal issues
    set hr= %time:~0,2%
    set hr=%hr: 0=%
    set t2=%time:~2,6%
    set /a ampm=hr/12
    if %ampm% equ 0 set ap=A
    set /a hr=hr”%%”12
    set /a hr=(12-hr)/12*12+hr
    set hr=0%hr%
    >> new.csv echo A, ABC, %d%%hr:~-2%%t2% %ap%M
    copy new.csv + xx.csv
    for /f %%a in (‘find /c /v “” ^<xx.csv’) do set lc=%%a
    >> new.csv echo t,%lc%
    ::========== end batch
    edit:
    TOTALLY missed the UTC requirement. My bad completely. Sorry!

    message edited by nbrane

    • 0