You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行fl(Format-List)命令后如何过滤输出结果中的空行

过滤输出空行的解决方案

你可以直接在原有管道后追加文本处理命令实现空行过滤,以下是几种最常用的方案:

  • 用grep实现(最简易)
    过滤完全空行:
    some_command_here | fl foo* | grep .
    
    同时过滤仅含空格、制表符的空白行:
    some_command_here | fl foo* | grep '\S'
    
  • 用awk实现
    利用空行字段数为0的特性过滤,执行效率更高:
    some_command_here | fl foo* | awk NF
    
  • 用sed实现
    显式匹配并删除空行:
    some_command_here | fl foo* | sed '/^$/d'
    
    同时删除仅含空白字符的行:
    some_command_here | fl foo* | sed '/^[[:space:]]*$/d'
    

上述任意命令执行后,你得到的输出会直接去掉所有空行,仅保留有效内容:

a fool and his money are soon parted
foot in the door
snafoo
foo-bar

内容的提问来源于stack exchange,提问作者einpoklum

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 06:15:04