【问题标题】:Batch: alternative to a multi-character eol批处理:替代多字符 eol
【发布时间】:2017-10-18 17:26:54
【问题描述】:

我正在使用批处理来解析另一个批处理文件。

我想通过基本设置来跳过 cmets

eol=rem

我还没有找到让它工作的方法。有没有其他方法可以做到这一点?

【问题讨论】:

  • 使用 findstr 找不到任何以 rem 开头的行。
  • 一些选项;使用带有Tokens=1*For 循环以及可能带有\<REM\> 的类似于Do If Not "%%A"=="REM", or use FindStr/V` 的东西。当我们看不到要解析的文件、解析方法或意图时,很难具体说明。
  • bxk21,您不应该将您的答案放入您的问题中,但是没有什么可以阻止您将其作为答案提交,并且如果它是您的首选接受它的话。请注意REM 不必是行上的第一个字符才有效,因此我建议\<REM\> 的原因是匹配整个单词 REM。目前还有任何以例如开头的连接行;远程、重新安装、可移除或剩余部分将是 removed,尽管它不是 remark。
  • @Compo,谢谢。我找到了一种在 findstr 中使用正则表达式查找所需内容的方法。

标签: batch-file for-loop eol


【解决方案1】:

我发现这是可行的:

for /F "tokens=*" %%A in ('findstr /b /v /i /r /C:"[    ]*rem[  ]" %BAT_FILE%') do (
    echo Uncommented Line: %%A
)

来自https://ss64.com/nt/findstr.html

/b searches from the beginning of the string
/v searches for lines not matching the string
/i allows for "REM" as well as "rem"
/r /C: turns on regex:
[   ] is a block containing a space and a tab.

因此,正则表达式搜索任意数量的空格,字符串“rem”,然后是一个空格。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多