如何使用windows findstr
命令搜索字符串的完全匹配?
例如:我只需找到字符串store
的完全匹配,但不能找到
stored
,storeday
等
以下命令返回所有字符串,store
,stored
和storeday
:
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%"
答案 0 :(得分:2)
根据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%"