windows上字符串搜索 findstr 命令的使用

2025-09-27 10:27:33

1、win + R 打开资源管理器输入: cmd 点击: 确定

在 cmd 里面输入: findstr /? 来查看 findstr 命令和参数的使用

语法:

       findstr [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file] [/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]strings [[drive:][path]filename[ ...]]

参数:

        /B 在字符串开始进行匹配

        /E 在字符串结尾进行匹配

        /L 搜索字符串

        /R 同上

        /S 在目录或则子目录进行搜索字符串

        /I  搜索不区分大小写字符

        /X  显示搜索到的字符串

        /V  显示没有搜索到的字符串

        /N  显示搜索到字符串,前面显示该字符所在的行号

        /M  搜索到匹配字符串,输出当前字符串的文件名

        /O  在每个匹配行前打印字符偏移量。

        /P   忽略有不可打印字符的文

        strings    要查找的字符串

        [drive:][path]filename 盘符路径及文件

2、文件开始行搜索字符串: findstr /b "http" a2.txt

windows上字符串搜索 findstr 命令的使用

3、文件结束行搜索字符串: findstr /e "html" a2.txt

windows上字符串搜索 findstr 命令的使用

4、搜索指定字符串: findstr /l "明天" art.txt

windows上字符串搜索 findstr 命令的使用

5、目录搜索指定字符串: findstr /s "html" *.txt

如果没有指定目录,以当前目录为准

windows上字符串搜索 findstr 命令的使用

6、忽略大小写搜索字符串: findstr /i "m" a2.txt

windows上字符串搜索 findstr 命令的使用

7、搜索完全匹配的行: findstr /x "apple(密码)" iphone.txt

windows上字符串搜索 findstr 命令的使用

8、搜索完全不匹配的行: findstr /v "明天" art.txt

windows上字符串搜索 findstr 命令的使用

9、输出字符串和所在的行号: findstr /n "明天" art.txt

windows上字符串搜索 findstr 命令的使用

10、搜索目录查找指定字符串: findstr /d:folder; "明天" "*.txt"

windows上字符串搜索 findstr 命令的使用

11、搜索多个目录查找字符串: findstr /d:a1;b2; "http" "*.txt"

搜索多个目录用分号进行分割

windows上字符串搜索 findstr 命令的使用

12、设定范围查序符串: findstr "[0-9]" a2.txt

windows上字符串搜索 findstr 命令的使用

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢