【发布时间】:2023-03-11 05:00:01
【问题描述】:
如何使用 Microsoft findstr 从单行“grep”一个项目?
我有这样一行:
<config>test</config><item>some data</item><date>2007-11-02</date><datestart>2007-10-31</datestart><path>d:\test\test\test.txt</path>
现在,如果我想对 <date> 和 </date> 中的内容进行 grep,我将如何编写该正则表达式?
需要注意的一点是,我必须将 findstr 命令放入 for 循环中,以便 grep 日期并将其存储在变量中。
示例:
for /f "Tokens=* Delims=" %%i in ('findstr /r /c:"regex" file.txt') do (
set date=%%i
set date=!date:-=!
)
另外,我不想依赖令牌,因为它们可能会有所不同。
【问题讨论】:
-
我觉得这个问题用
findstr是解决不了的。看我的回答。
标签: regex batch-file for-loop substitution findstr