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


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.

  • 3
    Wont grep -E '199[5-9]' file.txt do it?
    – clement
    Nov 19, 2015 at 16:35
  • yes it does, also egrep "199[5-9]" file.txt
    – lese
    Nov 19, 2015 at 16:39

1 Answer 1


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]"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .