Grep search for any number in a range

grepsearch

So I have a file with a number of records that look like the following:

Peugeot:206:2000:Red:1

And I'm trying to grep search for any that contain a year 1995-1999. I have tried

grep '[1995-1999]' file.txt

to no avail. Any ideas? Thanks.

Best Answer

This one is easy:

grep -E "199[5-9]"

does the job. It is easy, because the intended number range matches a character code range. For a more complicated example, e.g., 1998-2003, you will have to split the range appropriately:

grep -E "199[8-9]|200[0-3]"
Related Question