问题
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