批量读取txt然后拆分行换行,并在其他txt中写出

时间:2016-10-26 14:39:53

标签: batch-file

我有批处理问题。我需要用这一行读一个.txt

cod_est nro_prsna_clnte          cod_prdto                cod_sub_prdto            cod_cntto                fch_est                
------- ------------------------ ------------------------ ------------------------ ------------------------ -----------------------
C         777388304                       93                     2003             690005635940 2016-10-19 00:00:00.000

C         777388304                       93                     2003             690005635930 2016-10-18 00:00:00.000

单词之间有很多空格 我可以阅读de txt,但是行不能分割,结果就像这样留下了

C,777388304,93,2003,690005635940,2016-10-19
C,777388304,93,2003,690005635930,2016-10-18

这是我的代码:

for /F "tokens=* delims=:" %%i in (OFB_INF_PSN.txt) do (
    set t=
    for %%x in (%%i) do (
        echo %%x >> OFB_INF_PSN_2.txt
    )
)

1 个答案:

答案 0 :(得分:0)

for /F "tokens=1-6" %%i in (OFB_INF_PSN.txt) do echo %%i,%%j,%%k,%%l,%%m,%%n>> OFB_INF_PSN_2.txt

(请参阅文档提示中的for /? |more

令牌= 1-6表示制作6个令牌,%% i表示%% n

默认情况下,分隔符是 space (也是,;