我该如何检查,如果一些字符串* *开始在一批特定的词 [英] How do I check if some string *starts* with a specific word in batch

查看:115
本文介绍了我该如何检查,如果一些字符串* *开始在一批特定的词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何检查,如果一些字符串(从备案的文本文件行) 启动在一批特定的词吗?

How do I check if some string (line from a text file for the record) starts with a specific word in batch?

我知道如何检查字(子字符串)中的一句话/线(串)的存在,
但我怎么能检查天气是这个字的开始?

I know how to check if the word (sub-string) exists in the sentence/line (string), But how can I Check Weather it STARTS with this word?

感谢:)

推荐答案

这可以用 FINDSTR 是这样做的:

FINDSTR "^searchterm"

^ 在搜索前pression之初指定您专门在一行的开始寻找子。

The ^ at the beginning of a search expression specifies that you are looking for the substring specifically at the beginning of a line.

请注意,默认情况下 FINDSTR 执行区分大小写的搜索。要在不考虑搜索字母的大小写,指定 / I 开关:

Note that by default FINDSTR performs a case-sensitive search. To search regardless of letter case, specify the /I switch:

FINDSTR /I "^searchterm"

可以指定搜索源:

The source to search can be specified:


  • 作为参数:

  • as a parameter:

FINDSTR /I "^searchterm" filename



  • 使用标准输入重定向:

    FINDSTR /I "^searchterm" < filename
    



  • 使用管道:

  • using piping:

    command | FINDSTR /I "^searchterm"
    


    (在此情况下,源是输出的命令

    如果要搜索多个文件,尤其是当它们在同一个目录或目录树,它可能是最容易使用上述三种的第一个模式,因为 文件名 的在这种情况下可以做个面膜:

    If you want to search multiple files, particularly if they are in the same directory or directory tree, it is probably easiest to use the first pattern of the above three, because the filename in this case can be a mask:

    FINDSTR /I "^searchterm" D:\path\to\files*.ext
    

    以上将只在指定的目录中搜索文件。要搜索整个树,即包括所有的子目录,添加 / S 开关:

    FINDSTR /I /S "^searchterm" D:\path\to\files*.ext
    

    其他有用的选项可以在内置的帮助中(运行 FINDSTR /?)。

    Other useful options can be found in the built-in help (run FINDSTR /?).

    这篇关于我该如何检查,如果一些字符串* *开始在一批特定的词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆