Powershell: Filter the contents of a file by an array of strings

后端 未结 4 1462
[愿得一人]
[愿得一人] 2021-02-05 08:27

Riddle me this:

I have a text file of data. I want to read it in, and only output lines that contain any string that is found in an array of search terms.

If I

4条回答
  •  不思量自难忘°
    2021-02-05 08:42

    without regex and with spaces possible:

    $array = @("foo", "bar", "hello world")
    get-content afile | where { foreach($item in $array) { $_.contains($item) } } > FilteredContent.txt
    

提交回复
热议问题