[英]How to read file line by line using batch
Source file is present in below manner:- 源文件以以下方式存在:-
abc ABC
dfc DFC
adbc 中国农业发展银行
I am using below code to print the each line in the file. 我正在使用下面的代码来打印文件中的每一行。
for /f "tokens=* delims=" %%a in ('type input.txt') do (
set line=%%a
echo %line%
)
but the output is 但输出是
adbc 中国农业发展银行
adbc 中国农业发展银行
adbc 中国农业发展银行
What to do? 该怎么办? Required output is: 所需的输出是:
abc ABC
dfc DFC
adbc 中国农业发展银行
除非您特别需要操纵该行或将最后一行的内容保存在变量中,否则绝对不需要使用For
循环:
Type input.txt
@Squashman provided the answer really, but here it is written out: @Squashman确实提供了答案,但是在这里写出来:
setLocal EnableDelayedExpansion
for /f "tokens=* delims=" %%a in ('type input.txt') do (
set line=%%a
echo !line!
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.