grep for a range of numbers

Dear Friends,

I want to know how to grep for the lines that has a number between given range(start and end).

I have tried the following sed command.

sed -n -e '/20030101011442/,/20030101035519/p'

However this requires both start and end to be part of the content being grepped. However in my requirement, the range values may not be part of actual content.

input

1
4
6
8
10

range 2 to 9

output

4
6
8

Since 2 and 9 are not part of the input content. I don't get any output for the grep command.

Please help me out.

Thanks in advance,

Input:

$ cat fil
1
4
6
8
10

Output:

$ awk '$0 > 2 && $0 <9' fil
4
6
8

Guru.

1 Like

Guru,

Thanks for you reply. I am getting errors on passing the variable for the range limits.

awk -v a=$start -v b=$end '$0 > $a && $0 < $b' timestamp.log

awk: program limit exceeded: maximum number of fields size=32767
    FILENAME="timestamp.log" FNR=1 NR=1

Can you tell me what is the reason for error.

awk -v a=$start -v b=$end '$0 > a && $0 < b' timestamp.log
1 Like

Thanks Friends,

Considering your answers. I wonder if this is not possible by using SED command.