Q:

How to grep the following lines from a file?

I have a file which has the names of many files in a directory in the following format:
A20150824.0950-0955_jambala_CcnActiveSessionCounterJob
A20150824.0945-0950_jambala_CcnActiveSessionCounterJob
A20150824.0940-0945_jambala_CcnActiveSessionCounterJob
A20150824.0935-0940_jambala_CcnActiveSessionCounterJob
A20150824.0955-1000_jambala_CcnActiveSessionCounterJob
A20150824.0000-0005_jambala_CcnActiveSessionCounterJob
A20150824.0100-0105_jambala_CcnActiveSessionCounterJob
A20150824.0105-0110_jambala_CcnActiveSessionCounterJob
A20150824.0110-0115_jambala_CcnActiveSessionCounterJob
A20150824.0115-0120_jambala_CcnActiveSessionCounterJob
A20150824.0120-0125_jambala_CcnActiveSessionCounterJob
A20150824.1400-1405_jambala_CcnActiveSessionCounterJob

The naming convention of the above files is A<YYYYMMDD>.HHMM-HHMM_<city>_CcnActiveSessionCounterJob.
These files are created for every 5 minute for all the hours each day such that, for every hour i get 12 files and for every day 12X24 files. I have generated a file which has got the names of all the 12x24 files and have a while loop in bash script where I am trying to do some processing per hour. I want to find a way by which I could create another file which contains the 12 files for each hour. For this, I am having a while outer loop which gives the hour value and inner minute loop which gives the minutes value. These files has the time information in their names. Ex:
A20150824.0950-0955_jambala_CcnActiveSessionCounterJob

gives the information of 09-50 AM to 09-55 AM.
How do I use grep to extract the filenames from the file which contains all the 12X24 file names and put them in a separate file such that a new file contains the following file names:
A20150824.0900-0905_jambala_CcnActiveSessionCounterJob
A20150824.0905-0910_jambala_CcnActiveSessionCounterJob
A20150824.0910-0915_jambala_CcnActiveSessionCounterJob
A20150824.0915-0920_jambala_CcnActiveSessionCounterJob
.
.
.
A20150824.0955-1000_jambala_CcnActiveSessionCounterJob

I already have a variable hour which has the currently being processed hour information, I was trying to use the following but it doesn't work:
grep -E '.$hour' FILE_with_ALL_FILENAMES

where .$hour is targeted for .09 in the above file name. How do i fix this?

A:

Assuming:
hour=09

Just use that:
grep "\.$hour" file

With the single quotes in your example, the variable is not interpreted as variable. Therefore the pattern searches for $hour. Also the dot has to be escaped, else it would match any character.

