Windowsbatch file将空白字段更改为值

我正在写一个Windows脚本来读取一个txt文件中的9列数据,我想写这个数据到一个csv文件加载到数据库中。

我发现有一列有时是空白的,所以我想input代码“rdp”,另一列主要是数字,但是由于某些原因,某些值是'。'。 (大概表示值小于1.我想将这些值更改为“0”

我的代码

for /F %%b in (c:\ts_users\newfiles_list.txt) do ( for /F "tokens=1,2,3,4,5,6,7,8,9" %%i in (%%b) do ( echo %%i,%%j,%%k,%%l,%%m,!idle!,%%o %%p,%%q >>%%~nb.csv ) ) 

这pipe理阅读在TXT文件,然后把它写出一个CSV。 列k有时是空的,列n有时有'。'

我已经尝试了变化

  set var=rdp if %%k="" then set !k:=!var! 

这不起作用,所以我有点难倒(谷歌search了几天后)

当前input

 201401241611 USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME eu1ptsw002 201401241611 julie.noble rdp-tcp#9 3 Active 18 24/01/2014 14:24 eu1ptsw002 201401241611 svc.perfmon18 7 Disc 3 24/01/2014 14:15 eu1ptsw002 201401241611 reto.hofstetter 10 Disc 40 24/01/2014 10:57 eu1ptsw002 201401241611 lester.valentin 14 Disc 1:16 24/01/2014 11:53 eu1ptsw002 201401241611 philippe.bachmann 15 Disc 2 24/01/2014 12:45 eu1ptsw002 201401241611 patrik.soderlund rdp-tcp#2 21 Active 24 24/01/2014 07:42 eu1ptsw002 

电stream输出

 201401241611,USERNAME,SESSIONNAME,ID,STATE,,TIME LOGON,TIME 201401241611,julie.noble,rdp-tcp#9,3,Active,,24/01/2014 14:24,eu1ptsw002 201401241611,svc.perfmon18,7,Disc,3,,14:15 eu1ptsw002, 201401241611,reto.hofstetter,10,Disc,40,,10:57 eu1ptsw002, 201401241611,lester.valentin,14,Disc,1:16,,11:53 eu1ptsw002, 201401241611,philippe.bachmann,15,Disc,2,,12:45 eu1ptsw002, 201401241611,patrik.soderlund,rdp-tcp#2,21,Active,,24/01/2014 07:42,eu1ptsw002 

要求的输出

 201401241611,USERNAME,SESSIONNAME,ID,STATE,,TIME LOGON,TIME 201401241611,julie.noble,rdp-tcp#9,3,Active,18,24/01/2014 14:24,eu1ptsw002 201401241611,svc.perfmon18,rdp,7,Disc,3,24/01/2014 14:15,eu1ptsw002 201401241611,reto.hofstetter,rdp,10,Disc,40,24/01/2014 10:57,eu1ptsw002, 201401241611,lester.valentin,rdp,14,Disc,1:16,24/01/2014 11:53,eu1ptsw002 201401241611,philippe.bachmann,rdp,15,Disc,2,24/01/2014 12:45,eu1ptsw002 201401241611,patrik.soderlund,rdp-tcp#2,21,Active,24,24/01/2014 07:42,eu1ptsw002 

 @echo off &setlocal disableDelayedExpansion for /f "delims=" %%a in (file) do ( set "line=%%~a" setlocal enabledelayedexpansion set "line=!line:,.,=,0,!" set "line=!line:,,=,rdp,!" echo(!line! endlocal )