How to search a string in multiple files and return the names of files in Powershell?

后端 未结 11 1886
野的像风
野的像风 2020-11-30 15:57

I have started learning powershell a couple of days ago, and I couldn\'t find anything on google that does what I need so please bear with my question.

I have been a

11条回答
  •  执念已碎
    2020-11-30 16:34

    I modified one of the answers above to give me a bit more information. This spared me a second query later on. It was something like this:

    Get-ChildItem `
            -Path "C:\data\path" -Filter "Example*.dat" -recurse | `
        Select-String -pattern "dummy" | `
        Select-Object -Property Path,LineNumber,Line | `
        Export-CSV "C:\ResultFile.csv"
    

    I can specify the path and file wildcards with this structures, and it saves the filename, line number and relevant line to an output file.

提交回复
热议问题