PowerShell FINDSTR eqivalent?

后端 未结 8 951
栀梦
栀梦 2021-02-02 09:28

What\'s the DOS FINDSTR equivalent for PowerShell? I need to search a bunch of log files for \"ERROR\".

8条回答
  •  难免孤独
    2021-02-02 09:47

    Just to expand on Monroecheeseman's answer. gci is an alias for Get-ChildItem (which is the equivalent to dir or ls), the -r switch does a recursive search and -i means include.

    Piping the result of that query to select-string has it read each file and look for lines matching a regular expression (the provided one in this case is ERROR, but it can be any .NET regular expression).

    The result will be a collection of match objects, showing the line matching, the file, and and other related information.

提交回复
热议问题