windows 在 FOR 循环中使用什么分隔符来读取行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6721989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What delimiter to use in FOR loop for reading lines?
提问by sameold
I have a txt file that contains the following lines
我有一个包含以下几行的txt文件
jfo3 93jfl
lvls 29fdj
nskd jfuwe
xlkw eklwe
I'm trying to read the file line by line, and do something with it. What delimiter should I use?
我正在尝试逐行读取文件,并对其进行处理。我应该使用什么分隔符?
The delim I'm using here reads each word separately.
我在这里使用的 delim 分别读取每个单词。
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%x in (lines.txt) do (
echo %%x
)
回答by Moe Matar
This reads line by line for me:
这为我逐行读取:
for /f "delims=" %x in (lines.txt) do echo %x
回答by Aacini
The problem is not related to delims, but to tokens:
问题与 delims 无关,而与令牌有关:
for /f "tokens=*" %%x in (lines.txt) do echo %%x
回答by Siddharth
If this is your input file:
如果这是您的输入文件:
abc,def
ghi,jkl
mno,pqr
abc,def
吉,jkl
mno,pqr
then use
然后使用
FOR /F "tokens=1,2,3 delims=," %%i in (test.txt) do (whatever u want)