Reputation: 550
I have a file containing lines like:
121<some letters> random text ...
1234<some letters> random numbers etc...
Each line starts with a number followed by some letters.I'm looking for a way to select only the lines which start with a number in a specific interval, for example : [0-9999] . I'm having difficulty in selecting these lines if the number of digits can vary.
Tried using grep but can't seem to find the correct way to write the regex.
Upvotes: 1
Views: 4670
Reputation: 174696
Through grep,
grep -E '^([1-9][0-9]?[0-9]?[0-9]|[0-9])\b' file
Upvotes: 1
Reputation: 203219
awk '($1+0)>10 && ($1+0)<50' file
would print lines that start with a number from 11 to 49 inclusive.
Upvotes: 5