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

如何使用grep命令从现有过滤结果中仅筛选出Honda品牌车辆

筛选Honda品牌条目的grep命令方案

你可以直接在原有命令后通过管道追加上下文匹配的grep逻辑,实现仅保留Honda品牌的完整车辆条目:

# 基础过滤版本,保留默认分隔符
grep -A 4 L337 vehicles | grep -C 2 Blue | grep -B 4 6 | grep -B1 -A3 'Make: Honda'

# 进阶版本,去掉结果中多余的--分隔符
grep -A 4 L337 vehicles | grep -C 2 Blue | grep -B 4 6 | grep -B1 -A3 'Make: Honda' | grep -v '^--$'

参数说明

  • -B1:输出匹配Make: Honda行的前1行内容,对应车辆的牌照信息
  • -A3:输出匹配Make: Honda行的后3行内容,对应车辆的颜色、所有人、身高信息
  • grep -v '^--$':过滤掉结果里所有仅为--的分隔行

运行进阶版本命令后得到的结果如下:

License Plate L337QE9
Make: Honda
Color: Blue
Owner: Erika Owens
Height: 6'5"
License Plate L337DV9
Make: Honda
Color: Blue
Owner: Joe Germuska
Height: 6'2"
License Plate L3375A9
Make: Honda
Color: Blue
Owner: Jeremy Bowers
Height: 6'1"
License Plate L337WR9
Make: Honda
Color: Blue
Owner: Jacqui Maher
Height: 6'2"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 19:57:03