我有weather.txt
January,Snowy,02
February,Rainy,15
March,Sunny,25
和main.cmd
@echo off
for /f "tokens=1,3 delims=," %%M in (weather.txt) do (echo %%M %%T)
我期待输出
January 02
February 15
March 25
但是我得到了
January %T
February %T
March %T
帮助THX
答案 0 :(得分:0)
如果您在%%T
中执行了for
,则使用%%M
很奇怪。
cmd不能假定变量,它们必须按顺序排列。所以对于代币1和3,如果你从%% M开始,你需要下一个按字母顺序排列的字母才能显示该代币,而不仅仅是一个随机字母。因此,您的代码应该是:
@echo off
for /f "tokens=1,3 delims=," %%M in (weather.txt) do (echo %%M %%N)