Loop in shell script

Hi Friends, I have a file. the content is as below:
file1:

/A/B/C/abc.txt 
2013-07-28 13:50:00,2013-07-31 01:00:00,5,710 
/A/B/C/xyz.txt 
2011-09-21 18:30:00,2013-07-30 06:15:00,15,65135 
2009-11-09 18:00:00,2011-09-02 09:00:00,5,12345 
2013-07-28 13:50:00,2013-07-31 01:00:00,5,710  

Now I have to search the pattern "2013-07-28" in the file /A/B/C/abc.txt and the patterns "2011-09-21","2011-09-21" and "2013-07-28" in the file /A/B/C/xyz.txt The patterns are below the file name..
then my output would be like:

/A/B/C/abc.txt 2013-07-28 13:50:00,2013-07-31 01:00:00,5,710,searched pattern 
/A/B/C/xyz.txt 2011-09-21 18:30:00,2013-07-30 06:15:00,15,65135,searched pattern 
2009-11-09 18:00:00,2011-09-02 09:00:00,5,12345,searched pattern 2013-07-28 13:50:00,2013-07-31 01:00:00,5,710,searched pattern  

how to grep the pattern in the file whose name is in the same file where the pattern exists?????

Something like this?

#!/bin/bash

while read a1 a2
do
        [[ "$a1" =~ \/ ]] && file="$a1" || grep "$a1" "$file"

done < file

Your output doesn't seem consistent. I think you are probably intending to convert to what is called record format, where each line conveys it's "own context". I suggest awk not grep. Here is a starting point:

$ cat a.a
/A/B/C/abc.txt 
2013-07-28 13:50:00,2013-07-31 01:00:00,5,710 
/A/B/C/xyz.txt 
2011-09-21 18:30:00,2013-07-30 06:15:00,15,65135 
2009-11-09 18:00:00,2011-09-02 09:00:00,5,12345 
2013-07-28 13:50:00,2013-07-31 01:00:00,5,710


$ awk '/^\//{file=$0}/^[0-9]/ {print file,$0}' a.a
/A/B/C/abc.txt  2013-07-28 13:50:00,2013-07-31 01:00:00,5,710 
/A/B/C/xyz.txt  2011-09-21 18:30:00,2013-07-30 06:15:00,15,65135 
/A/B/C/xyz.txt  2009-11-09 18:00:00,2011-09-02 09:00:00,5,12345 
/A/B/C/xyz.txt  2013-07-28 13:50:00,2013-07-31 01:00:00,5,710

Here is the same example, but this time using an awk file, because placing awk script on the command line can sometimes be confusing

$ cat x.awk
/^\//    {file=$0}
/^[0-9]/ {print file,$0}


$ cat a.a
/A/B/C/abc.txt 
2013-07-28 13:50:00,2013-07-31 01:00:00,5,710 
/A/B/C/xyz.txt 
2011-09-21 18:30:00,2013-07-30 06:15:00,15,65135 
2009-11-09 18:00:00,2011-09-02 09:00:00,5,12345 
2013-07-28 13:50:00,2013-07-31 01:00:00,5,710


$ awk -f x.awk a.a
/A/B/C/abc.txt  2013-07-28 13:50:00,2013-07-31 01:00:00,5,710 
/A/B/C/xyz.txt  2011-09-21 18:30:00,2013-07-30 06:15:00,15,65135 
/A/B/C/xyz.txt  2009-11-09 18:00:00,2011-09-02 09:00:00,5,12345 
/A/B/C/xyz.txt  2013-07-28 13:50:00,2013-07-31 01:00:00,5,710

I did not account for the "searched pattern" part of your records, but this is a starting point only and hope the use of awk in this fashion can help. Look at BEGIN and END statements in awk as well.