【问题标题】:Is it possible to use egrep to match numbers within a range?是否可以使用 egrep 匹配范围内的数字?
【发布时间】:2013-10-11 13:46:56
【问题描述】:

有没有办法在两组数字之间grep/egrep

egrep "SomeText [19999-22000]" /some/file.txt

它没有返回值。我期望:

SomeText 19999 ffuuu  
SomeText 20001 ffuuu  
SomeText 21000 ffuuu  

【问题讨论】:

  • 这与 SO 无关;属于Super User
  • @JimGarrison Grep 和正则表达式都是 Stack Overflow 上的主题。这就是我们为它们设置标签的原因。

标签: regex grep integer


【解决方案1】:

regex 不是数学东西的正确工具(尽管有时它可以做到),在你的情况下,试试 awk:

awk '$2>=19999 && $2<=22000' file

【讨论】:

    【解决方案2】:

    您可以使用范围函数,awk

    awk '$2=="19999",$2=="22000"' file
    SomeText 19999 ffuuu
    SomeText 20001 ffuuu
    SomeText 21000 ffuuu
    

    【讨论】:

      猜你喜欢
      • 2017-06-20
      • 2017-06-18
      • 2022-01-10
      • 1970-01-01
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多