格式:
FOR /F ["options"] %%i IN (file) DO command
FOR /F ["options"] %%i IN ("string") DO command
FOR /F ["options"] %%i IN ('command') DO command
这个可能是最常用的,也是最强的命令,主要用来处理文件和一些命令的输出结果。
file代表一个或多个文件
string 代表字符串
command代表命令
["options"] 可选
对于FOR /F %%i IN (file) DO command
rem 逐行读取
for /f %%i in (a.txt) do echo %%i
rem 以 空格 分割,读取第2列,然后遍历每行
for /f "tokens=2 delims= " %%i in (a.txt) do echo %%i