Changing value of a specific field based on a diff field
Posted: 12 Aug 2011 08:21
I am trying to read the 9th, 11th, 13th, 15th and 17th fields in each line and if they are blank, remove the value from the previous field. I have numerous bugs here, the most obvious of which is that I can't figure out how to change the value associated with the token and write it back to the line variable before writing the line to the output file. I need help, and a lot of it.
This isn't actually code but I didn't want to lose the formatting. It is a small file sample. As you can see, there is a header line, which the test would ignore because there are no blank values in it.
Code: Select all
for /f "tokens=*" %%a in (infile.csv) do (
set line=%%a
setlocal enableDelayedExpansion
for /f "tokens=8-17 delims=," %%h in ("!line!") do (
if "%%i"== set "%%h"=
if "%%k"== set "%%j"=
if "%%m"== set "%%l"=
if "%%o"== set "%%n"=
if "%%q"== set "%%p"=
)
echo !line!>>outfile.txt
)
This isn't actually code but I didn't want to lose the formatting. It is a small file sample. As you can see, there is a header line, which the test would ignore because there are no blank values in it.
Code: Select all
Co Code,Batch ID,File #,Pay #,Shift,Reg Hours,O/T Hours,Hours 3 Code,Hours 3 Amount,Hours 4 Code,Hours 4 Amount,Hours 4 Code,Hours 4 Amount,Hours 3 Code,Hours 3 Amount,Hours 4 Code,Hours 4 Amount
5G6,40,101165,1,2,40,4.9,D,,V,,H,,O,,B,12:00
5G6,40,10047,1,2,40,3.9,D,,V,6:00,H,,O,10:00,B,
5G6,40,133,1,2,40,5.4,D,4:00,V,,H,8:00,O,,B,