【问题标题】:Simple Terminal Command Question - Is there a command to pull a certain line out of an input?简单的终端命令问题 - 是否有从输入中拉出某一行的命令?
【发布时间】:2010-07-12 05:55:18
【问题描述】:

我有一个简单的问题。有没有一个命令可以让你从输入中拉出某一行?就像我想要 ifconfig 的第 7 行一样。有没有办法做到这一点:ifconfig | [command] 7

谢谢!

【问题讨论】:

    标签: command-line terminal grep


    【解决方案1】:

    您可以使用 sed 从文件和/或标准中提取特定行,如下所示

    sed -n '7p' filename

    some_command | sed -n '7p'
    

    【讨论】:

      【解决方案2】:

      应该这样做

      ifconfig | head -n 7 | tail -n 1

      【讨论】:

      • 或者,更简洁一点:ifconfig | head -7 | tail -1
      猜你喜欢
      • 1970-01-01
      • 2010-09-09
      • 1970-01-01
      • 1970-01-01
      • 2021-11-25
      • 2018-08-07
      • 1970-01-01
      • 2015-02-15
      • 1970-01-01
      相关资源
      最近更新 更多