批量文件循环使用""

时间:2016-12-06 21:23:38

标签: batch-file

我试图像这样循环一个文本文件:

"11/05/2016",Paris,Snowy,02
N/A,February,London,15
"11/05/2016",Berlin,Sunny,25

使它看起来像这样:

2016/11/05,Paris,Snowy,02
N/A,London,Rainy,15
2016/11/05,Berlin,Sunny,25

我坚持

FOR /F "tokens=1,2,3* delims=,/" %%G IN (weather.txt) DO @echo %%I %%G %%H %%J

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

@ECHO OFF
SETLOCAL EnableExtensions
FOR /F "usebackq tokens=1,* delims=," %%G IN ("weather.txt") DO (
  FOR /F "tokens=1-3 delims=/" %%g IN ("%%~G") DO (
    if "%%~i"=="" (
      rem N/A                 input -> output
      echo(%%~G,%%~H
    ) else (
      rem 11/05/2016          input
      echo(%%i/%%g/%%h,%%H
      rem 2016/11/05          output
    )
  )
)

%%G%%g循环中的令牌模板如下:

G            H
"11/05/2016",Paris,Snowy,02
 g  h  i

G   H
N/A,London,Rainy,15
g h                     3rd token (%%i) is empty