Including EOL in egrep pattern for multiple lines

Hi all

I need your help to get a high-performance solution.
I am working on a extensive script to automate file restores using the bprestore tool on a Solaris 5.10 server (bash 3.00). I will only paste the needed parts of the script to avoid any confusion.
To use the script the user has to create a file "filelist" within his home directory, including the request number of the file restore on the first line, followed by all filenames which should be restored line by line, first.
The script gets these filenames by a for loop:

fcntr=0
flnms=("")
for flnm in `cat $HOME/filelist`
  do    
    if [ ${fcntr} -eq 0 ]
      then
        rnmbr=${flnm}
        fcntr=$((fcntr+1))
      else
        flnms=(${flnms[@]} ${flnm}) 
    fi
  done

Next step is to get all absolute paths for each file using the bplist tool:

sudo /usr/openv/netbackup/bin/bplist -l -B -R -C ${servername} -b -s ${startdate} -e ${enddate} ${stdsrchpth} | while read filename
  do 
    for file in ${flnms[@]}
      do
        echo ${filename} | grep  "/${file}$" >> ${tmplst}
      done
  done

or

for file in ${flnms[@]}
  do
    sudo /usr/openv/netbackup/bin/bplist -l -B -R -C ${servername} -b -s  ${startdate} -e ${enddate} ${stdsrchpth} | grep "/${file}$" | while read filename
      do
        echo ${filename} >> ${tmplst}
      done
  done

These would be solutions which work as they should... but:
bplist returns more than six million lines which means a very time consuming process.

I tried to use egrep:

sudo /usr/openv/netbackup/bin/bplist -l -B -R -C ${servername} -b -s  ${startdate} -e ${enddate} ${stdsrchpth} | egrep "\/file1\$|file2\$|etc.." >> ${tmplst}

Without the \$ part it worked quite fast, but I have to include \$ because the script should not match "file1.data.cdi" if it is searching for "file1.data". I wonder if there is a way to do it like this (including $ as EOL, not as EOF like it happens with the syntax above):

sudo /usr/openv/netbackup/bin/bplist -l -B -R -C ${servername} -b -s  ${startdate} -e ${enddate} ${stdsrchpth} | egrep ${flnms[@]} >> ${tmplst}

The script should go through the list of files from bplist only once and directly gets all absolute paths for the files within the array ${flnms[@]} using "\/file1\$|\/file1\$|etc..." as syntax.

Many thanks for your help.

You could try:

sudo /usr/openv/netbackup/bin/bplist ...  | grep -f <(sed 's|^|/|; s|$|$|' "$HOME/filelist") > "${tmplst}"

Your suggestion will not work. Let my explain why:
There are not only the filenames listet in ${HOME}/filelist (I will update the main post too). The first line of filelist contains the request number of the file restore which is needed to create a appropriate directory where the files should be restored to. There is no general syntax for the request numbers which could be captured by regex.

fcntr=0
flnms=("")
for flnm in `cat $HOME/filelist`
  do    
    if [ ${fcntr} -eq 0 ]
      then
        rnmbr=${flnm}
        fcntr=$((fcntr+1))
      else
        flnms=(${flnms[@]} ${flnm}) 
    fi
  done

I could create a new temporary file and use it as you have mentioned above:

myfls="${stddestpath}/myfls.txt"
for flnm in ${flnms[@]}
  do
    echo -e "${flnm}" >> ${myfls}
  done

sudo /usr/openv/netbackup/bin/bplist ...  | grep -f <(sed 's|^|/|; s|$|$|' "${myfls}") > "${tmplst}"

But it does not seem to be a very good solution because I want to avoid any sources of errors. The script should create as few temporary files as possible (two are needed by bprestore, one to change the destination path of restore and one which contains a list of all absolute paths).