Reputation: 713
I have a file query.txt, each line of the file represents a number, using grep command i have to find all lines that have a number 10 < x < 100
How should i write it ?
Upvotes: 0
Views: 104
Reputation: 4317
As noted by others, grep
is not the best tool to use in this context. But, if you absolutely must...
grep -E '^((1[1-9])|([2-9][0-9]))$'
Upvotes: 0
Reputation: 43107
Off the top of my head:
grep "^..$" query.txt | grep -v 10
Note that this only works because your range happens to coincide with 'all two digit numbers except 10'.
Upvotes: 2
Reputation: 4286
This might work for you, as long as your requirement is actually 10 <= x < 100
, as it would include 10
:
grep ^..$ query.txt
Upvotes: 0
Reputation: 195179
grep is the wrong tool to use.
try this one-liner:
awk '($0+0)>10 && ($0+0)<100' file
Upvotes: 3