Skip to content

Instantly share code, notes, and snippets.

@awwsmm
Created July 19, 2018 16:29
Show Gist options
  • Save awwsmm/672921b09f60ae249cf3b18b9f539a4b to your computer and use it in GitHub Desktop.
Save awwsmm/672921b09f60ae249cf3b18b9f539a4b to your computer and use it in GitHub Desktop.
Add constant columns to CSV with batch script
@echo off
setlocal enabledelayedexpansion
set row=0
set inFile=merged.csv
set outFile=final.csv
if exist "%outFile%" del "%outFile%"
>%outFile% (
for /f "tokens=1,* delims=," %%A in (%inFile%) do (
set /A row+=1
set time=%%A
set data=%%B
REM : edit column headers and values here
set head=machine,label
set body=0,inlet-sparger
if !row! lss 2 (
REM : I have no idea why this needs to be separated
REM : ...but it has to, or it doesn't work
echo | set /p=!time!
echo | set /p=,!head!,
echo !data!
) else (
echo !time!,!body!,!data!
)
)
)
if exist "%inFile%" del "%inFile%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment