remove empty lines from text file with PowerShell

后端 未结 11 1811
情话喂你
情话喂你 2020-12-08 19:32

I know that I can use:

gc c:\\FileWithEmptyLines.txt | where {$_ -ne \"\"} > c:\\FileWithNoEmptyLines.txt

to remove empty lines. But How

11条回答
  •  一整个雨季
    2020-12-08 20:07

    This will remove empty lines or lines with only whitespace characters (tabs/spaces).

    [IO.File]::ReadAllText("FileWithEmptyLines.txt") -replace '\s+\r\n+', "`r`n" | Out-File "c:\FileWithNoEmptyLines.txt"
    

提交回复
热议问题