从输出中删除空行? [英] Remove blank lines from output?

查看:48
本文介绍了从输出中删除空行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行这个命令时,它返回带有很多空行的输出.

When I run this command, it returns the output with lots of blank lines.

Get-Host | Select Name, Version | Format-List

我尝试使用 ExpandProperty 但它仍然在输出的末尾留下一个空行,有没有办法删除最后一个空行?

I tried using ExpandProperty but it still leaves me with one blank line at the end of the output, is there a way to remove the last blank line?

Get-Host | Select -ExpandProperty Name, Version | Format-List 

推荐答案

如果你真的需要Format-List提供的格式,那么你可以使用Out-String和 Trim() 去除空行:

If you really need the format that Format-List provides, then you can use Out-String and Trim() to get rid of empty lines:

Get-Host | Select Name,Version | Format-List | Out-String | ForEach-Object { $_.Trim() }

但是,根据您的需要,使用 CSV 或 JSON 格式进行进一步处理可能更容易(请参阅 ConvertTo-JsonConvertTo-Csv).

But, depending on your needs, it's probably easier to just use CSV or the JSON format for further processing (see ConvertTo-Json or ConvertTo-Csv).

这篇关于从输出中删除空行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆