gpt4 book ai didi

windows - 如何使用 windows `findstr` 命令搜索字符串的精确匹配?

转载 作者:可可西里 更新时间:2023-11-01 10:16:35 24 4
gpt4 key购买 nike

如何使用 windows findstr 命令搜索字符串的精确匹配?例如:我只需要找到完全匹配的字符串 store 而不是storedaystoreday

以下命令返回所有字符串,storestoredstoreday:

findstr /l /s /i /m /c:"store" "c:\test\*.txt"

完整脚本:

set "manifest_folder=C:\Calc_scripts*.*"
set "file_list=C:\Search_results\Search_Input.txt"
set "outputfile=C:\Search_results\Search_results.txt"
(for /f "usebackq delims=" %%a in ("%file_list%") do (
set "found="
for /f "delims=" %%b in ('findstr /r /s /i /m /c:"%%a" "%manifest_folder%"') do (
echo %%a is found in %%~nxb
set "found=1"
)
if not defined found (
echo %%a is not found
)
))> "%outputFile%"

最佳答案

根据findstr /?帮助,\<\>表示单词边界——请参阅以下摘录:

Regular expression quick reference:
. Wildcard: any character
* Repeat: zero or more occurrences of previous character or class
^ Line position: beginning of line
$ Line position: end of line
[class] Character class: any one character in set
[^class] Inverse class: any one character not in set
[x-y] Range: any characters within the specified range
\x Escape: literal use of metacharacter x
\<xyz Word position: beginning of word
xyz\> Word position: end of word

因此你需要改变你的findstr像这样的命令行:

findstr /r /s /i /m /c:"\<store\>" "c:\test\*.txt"

所以在你的完整脚本中它应该是这样的:

findstr /r /s /i /m /c:"\<%%a\>" "%manifest_folder%"

关于windows - 如何使用 windows `findstr` 命令搜索字符串的精确匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38857449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com