SyntaxFix
Write A Post
Hire A Developer
Questions
Not specifically using -replace, but you get the same effect parsing the content using -notmatch and regex.
-replace
-notmatch
(get-content 'c:\FileWithEmptyLines.txt') -notmatch '^\s*$' > c:\FileWithNoEmptyLines.txt