Windows 字符串过滤命令 findstr

2023-05-11  本文已影响0人  饱饱抓住了灵感

findstr是Windows命令行中的一个工具,用于在文件中查找字符串。它可以在单个文件或多个文件中查找指定的字符串,并返回包含该字符串的行。它还可以使用正则表达式进行高级搜索。

findstr的语法如下:

findstr [/b] [/e] [/l] [/r] [/s] [/i] [/x] [/v] [/m] [/n] [/o] [/g:file] [/f:file] [/c:string] [/p] [/offline] [/d:dirlist] [/a:ColorAttribute] [/nologo] [strings] [[drive:][path]filename[ ...]]

其中,常用的参数包括:

例如,要在当前目录下的所有txt文件中查找包含字符串“hello”的行,可以使用以下命令:

findstr "hello" *.txt

如果要忽略大小写,可以使用参数/i:

findstr /i "hello" *.txt

如果要在子目录中搜索,可以使用参数/s:

findstr /s "hello" *.txt

如果要使用正则表达式进行匹配,可以使用参数/r:

findstr /r "he.*o" *.txt



另外,还可以将findstr命令与其他命令通过管道符连接起来,以实现更复杂的操作。例如,可以使用findstr命令来过滤文件内容,并将结果传递给其他命令进行进一步处理。例如:

dir | findstr ".txt" | sort
上一篇 下一篇

猜你喜欢

热点阅读