【问题标题】:Linux grep command with relevant values as output具有相关值作为输出的 Linux grep 命令
【发布时间】:2017-08-28 21:40:52
【问题描述】:

内容:

1. Name : Jack
   Address : Toronto
   Age : 21
2. Name : Mitchelle
   Address : Newyork
   Age : 67
3. Name : John
   Address : Toronto
   Age : 33

命令grep Toronto 给我

Address : Toronto
Address : Toronto

预期结果:

1. Name : Jack
   Address : Toronto
   Age : 21
3. Name : John
   Address : Toronto
   Age : 33

【问题讨论】:

  • 你是在问“我怎样才能得到整个地址块而不是一行”?

标签: linux unix grep


【解决方案1】:

对于您的情况,您需要关心一行前导和一行尾随上下文,因此 grep -C1 Toronto input 应该这样做。

【讨论】:

    猜你喜欢
    • 2021-03-29
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 2017-04-28
    • 2013-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多