是否有可能使用egrep来匹配范围内的数字? [英] Is it possible to use egrep to match numbers within a range?

查看:192
本文介绍了是否有可能使用egrep来匹配范围内的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  egrepSomeText [19999-22000]/some/file.txt 

它没有返回值。我希望:
$ b $ pre $ SomeText 19999 ffuuu
SomeText 20001 ffuuu
SomeText 21000 ffuuu

解决方案正则表达式不是正确的数学工具(虽然有时它可以),但是,正则表达式并不是正确的工具。在你的情况下,尝试使用awk:

  awk'$ 2> = 19999&& $ 2 <= 22000'文件


Is there a way to grep/egrep between two sets of numbers?

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

It's not returning the values. I expect:

SomeText 19999 ffuuu  
SomeText 20001 ffuuu  
SomeText 21000 ffuuu  

解决方案

regex is not the right tool for math stuff (although sometimes it can do), in your case, try the awk:

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

这篇关于是否有可能使用egrep来匹配范围内的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆