cmd findstr 字符串查找增强使用说明

2019-01-30 05:22:02于海丽

9.用文本制定要查找的文件 And 用文本制定要查找的字符串
用文本制定要查找的文件
新建一个file.txt,内容如下(这个文本中指定findstr要查找的文本的路径):

C:UsershelloworldDesktop1.txt
C:UsershelloworldDesktopa.txt
C:UsershelloworldDesktopclip.txt
C:UsershelloworldDesktopCrLf 批处理笔记.txt
C:UsershelloworldDesktopfile.txt
C:UsershelloworldDesktopMyRarHelp.txt
C:UsershelloworldDesktoptest.txt
C:UsershelloworldDesktop红楼.txt
C:UsershelloworldDesktop520新建文本文档.txt
C:UsershelloworldDesktop52012hello_ world.txt
C:UsershelloworldDesktop编程help.txt
C:UsershelloworldDesktop编程win7 help比xp help多出来的命令.txt
C:UsershelloworldDesktop编程wmic.txt

代码:

C:UsershelloworldDesktop>findstr /f:file.txt /im "hello"

效果:

C:UsershelloworldDesktop1.txt
C:UsershelloworldDesktopa.txt
C:UsershelloworldDesktopCrLf 批处理笔记.txt
C:UsershelloworldDesktopfile.txt
C:UsershelloworldDesktoptest.txt

用文本制定要查找的字符串
新建一个string.txt,内容如下(这个文本中指定findstr要查找的字符串):

^hello
world

a.txt

^hello
hello
hello hello
good hello
你好 hello
Hello World
Hello Boy
hello ,good man.
goodbye!

代码:

C:UsershelloworldDesktop>findstr /ig:string.txt a.txt

效果:

hello
hello hello
Hello World
Hello Boy
hello ,good man.

被忽略的行

^hello
good hello
你好 hello
goodbye!

从被忽略的“^hello”可以看出,在不加/l参数的前提下,用/g指定的搜索字符串中如果含有“元字符”,则作为正则表达式使用,而不是作为普通表达式。
10.搜索一个完全匹配的句子
其实findstr自带的帮助中就有个很好的例子:
例如: 'FINDSTR "hello there" x.y' 在文件 x.y 中寻找 "hello" 或
"there"。'FINDSTR /C:"hello there" x.y' 文件 x.y 寻找
"hello there"。
可以以这个例子来做个测试。

a.txthello there
hellothere
hello
there

代码:

C:UsershelloworldDesktop>findstr /ic:"hello there" a.txt
相关文章 大家在看