Powershell's out-file clears the file when piped from itself

后端 未结 2 2001
死守一世寂寞
死守一世寂寞 2021-01-25 10:44

I am working with the following command:

get-content C:\\somepath\\Setup.csproj | 
        select-string -pattern \'\'          


        
2条回答
  •  -上瘾入骨i
    2021-01-25 11:11

    Could you please try this:

    $filtered_content = Get-Content C:\somepath\Setup.csproj | select-string -pattern '' -NotMatch ;
    Remove-Item C:\somepath\Setup.csproj -Force  ;
    New-Item C:\somepath\Setup.csproj -type file -force -value "$filtered_content"  ;
    

    Tested in local with one file.

提交回复
热议问题