text - How to add constant value to CSV using batch file? -


i have bunch of csv files want add constant value before merge them know csv file each row came from. using simple batch file merge csv files, need identifier sort merged file on.

copy *.csv importfile.csv  

so need add constant column of 1's each row in csv-a, constant column of 2's csv-b, 3's csv-c etc..... before merging files.

i sure possible, have no idea start? can help?

another option be.....

if row in column k in csv-a.csv = "certain value"  change "1"  else nothing  

@echo off setlocal set "sourcedir=." set "filemask=csv*.csv" ( /f "tokens=1*delims=[]" %%c in (    'dir /b /a-d /on "%sourcedir%\%filemask%" ^|find /n /i ".csv"'    ) (    set "firstrow=y"    /f "usebackqdelims=" %%r in ("%sourcedir%\%%d") (     if defined firstrow if %%c==1 echo sourcefile,%%r     if not defined firstrow echo %%c,%%r     set "firstrow="    ) ) )>importfile.csv 

set directory , filemask appropriate, then
- build directory of target files, /b in basic form (filename only) /a-d ignore directorynames /on in order of name - find ".csv" (which occur in each line) /i in case /n , number them in [] - "tokens=1*delims=[]" options assigns number %%c , filename %%d

for each file found,
- flag processing first row - read each line file %%r - if it's first row in file#1, add "sourcefile," header line - if it's not first row, output file#, prefixed row text - clear 'first row' flag

note output filename should not match filemask chosen. it's fine produce .txt file instance , rename it.

i've assumed need treat first row specially. if don't rem-out set "firstrow=y" line rem keyword (easiest option)

of course, if echo %%d,%%r instead of echo %%c,%%r source filename rather serial number of file appear (and few other simplifications made - that's easiest option if choose)


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -