Is it possible to use egrep to match numbers within a range?

僤鯓⒐⒋嵵緔 提交于 2020-01-11 07:45:10

问题


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  

回答1:


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



回答2:


You can use the range function , with awk

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


来源:https://stackoverflow.com/questions/19307006/is-it-possible-to-use-egrep-to-match-numbers-within-a-range

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!