本文介绍了如何禁用`for/F`的`eol`和`delims`选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

带有 /F 开关的 for 命令用于解析文本字符串的行(文字字符串,从文本文件中读取,或从命令行输出中检索)和将每一个解析为一个或多个标记.

The for command with the /F switch is used to parse lines of text strings (literal strings, read from text files, or retrieved from command line output) and to parse each to one or more tokens.

如何获得一行文本,而不替换任何字符或忽略任何行?

How can I get a line of text as it is, without any characters replaced nor any lines ignored?

我知道 for/F "delims=" %L in (*) do echo."%L" 返回每个未编辑的解析(非空)行.但是,由于 eol 选项默认为 ;,因此以该字符开头的每一行都将被忽略.
如果我使用 for/F "tokens=* eol=" %L in (*) do echo."%L"[ [ This claim is not true, "eol=" does not disable the eol option, but it defines " as the eol character!], but the delims option defaults to space and tab, so any leading spaces and/or tabs become removed.
(Use %%L within batch files. The * stands for any valid source of text string here.)

所以我的问题换句话说:有没有办法指定 no delims and no eol 字符?

So my question in other words: is there a way to specify no delims and no eol characters?

我尝试指定两个选项字符串 ("eol=" "delims="),但这会导致语法错误.选项字符串"eol=delims="也是如此.

I tried to specify two option strings ("eol=" "delims=") but such results in a syntax error. So does option string "eol=delims=".

注意:这个问题在标记化时不会持续存在,也就是说,当设置了 delims 选项时,因为它似乎以比 eol(奇怪但幸运的是),因此您可以通过将 delims 字符也指定为 delims 来隐藏"eoldelims代码>eol.

Note: This problem does not persist when tokenizing, that is, when the delims option is set, because that seems to be applied with a higher priority than eol (strangely but luckily), so you can "hide" eol behind delims by specifying a delims character also as eol.

推荐答案

1) 你永远无法强制 bat 不忽略空/仅分隔符 行.这可以通过管道传递到 findstr/R/N "^" 命令和使用诸如 "tokens=1* delims=:" 之类的选项并仅获取第二个令牌

1) you will be never able to force bat to not ignore empty / delimiter-only lines.This can be (sort-of) worked around by piping to findstr /R /N "^" command and use options like "tokens=1* delims=:" and get only the second token

2) 要同时停用 eol 和 delim,您可以使用此语法:

2) To deactivate eol and delim at the same time you can use this syntax:

For /f tokens^=*^ delims^=^ eol^= %%a in (file.txt) do echo.%%a

虽然空行仍然会被忽略.

though the empty lines still will be ignored.

这篇关于如何禁用`for/F`的`eol`和`delims`选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 18:08