使用PowerShell从文本文件中删除空行 [英] remove empty lines from text file with PowerShell
本文介绍了使用PowerShell从文本文件中删除空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以使用:
gc c:\FileWithEmptyLines.txt | where {$_ -ne ""} > c:\FileWithNoEmptyLines.txt
以删除空行.但是我如何用'-replace'删除它们?
to remove empty lines. But How I can remove them with '-replace' ?
推荐答案
I found a nice one liner here >> http://www.pixelchef.net/remove-empty-lines-file-powershell. Just tested it out with several blanks lines including newlines only as well as lines with just spaces, just tabs, and combinations.
(gc file.txt) | ? {$_.trim() -ne "" } | set-content file.txt
有关该代码的一些注释,请参见原始文档.不错:)
See the original for some notes about the code. Nice :)
这篇关于使用PowerShell从文本文件中删除空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文