Remove last line from file with Powershell

Viewed 43286

I am using

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

to remove the empty lines that SSRS puts at the bottom of my CSVs.

However, the last line, which has data on it, ends with a CRLF (as viewed in Notepad++) - and this is not removed, so technically there is still a blank line at the bottom of the file.

Is there a way to remove this CRLF from the last line (and keep the data intact, of course)?

5 Answers
Related