【问题标题】:grep with negative condition, and more than a certain line number带有否定条件的 grep,并且超过某个行号
【发布时间】:2011-01-10 02:36:00
【问题描述】:

我正在尝试为文件中的条件编写 grep/sed/awk,同时使用否定条件(不包含 xxx),并且我想 grep 所有 > 的行特定的行号。

【问题讨论】:

  • 请允许我欢迎您来到 StackOverflow,并提醒您我们通常在这里做的三件事:1) 当您收到帮助时,请尝试在您的领域中回答问题专业知识 2) Read the FAQ!! 3) 当你看到好的问题和答案时,给他们投票using the gray triangles,因为系统的可信度是基于用户通过分享他们的知识而获得的声誉。还记得接受更好地解决您的问题的答案,如果有的话,by pressing the checkmark sign

标签: shell unix sed awk grep


【解决方案1】:

Awk 应该可以很好地处理这个问题:

/condition/ && ! /negative condition/ { print $0; outputdone = 1 }

{ if(NR > certain_line_number && !outputdone) print $0
  outputdone = 0
}

我不太确定所有条件是否一起应用。我猜你总是想打印超出某个点的行,但在此之前应用了正负条件。

【讨论】:

  • 您可以将其缩短为 awk '(/condition/&&!/negative condition/)||NR>certain_line_number)'。您仍然可以包含您的 outputdone 标志,但我不明白为什么需要它。
【解决方案2】:
tail -<number of lines that you want from end of file>  filename | grep -v xxx

【讨论】:

  • 这更好,但对我不起作用,因为我保存了我阅读的最后一行并且文件继续增长,所以从技术上讲我不知道我需要阅读的行数跨度>
  • 这也不包括 OP 要求的(肯定的)条件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-09-25
  • 2018-03-14
  • 2018-08-28
  • 1970-01-01
  • 1970-01-01
  • 2020-11-27
  • 2016-01-24
相关资源
最近更新 更多