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

2019-09-19 06:51:10于丽


因为,当你使用“普通字符串模式”,findstr不会把^当做是正则表达式的元字符,而只是把其当做普通字符^,也就是说它此时已经不具备“表示行首”的功能,变成了和h之类字符一样的普通民众,再也没“特权”。
改变a.txt的内容:^hello

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

再次运行代码:

C:UsershelloworldDesktop>findstr /nli "^hello" a.txt

结果:

1:^hello

7.查找不包含指定字符的行
如果比较一下find和findstr命令就会发现,他们都具有/v,/n,/i,/off[line]参数,而且功能都是一摸一样的,这里说的就是/v参数。
查找不包含hello的行。
代码:

C:UsershelloworldDesktop>findstr /vni "hello" a.txt

结果:

9:goodbye!

8.如何查找当前目录及子目录下文件内容中包含某字符串的文件名?
在写这篇教程的时候,偶然看到有批友问了这个问题,问题地址:http://bbs.bathome.net/viewthread.php?tid=14727
代码:

findstr /ms "专业" *.txt

效果:
找出当前目录及子目录下文件内容中包含“专业”的文本文件,并只显示其文件名。
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!

代码:
相关文章 大家在看