function getSumFileName() { echo $1 | sed "s/images/sumfiles/" \ | sed "s/F[0-9]_2P_IOF_DBL.FIT/.SUM/" \ | sed "s/F[0-9]_2P_CIF_DBL.FIT/.SUM/" } while read -r line; do imagefile=/project/nearsdc/data/$line sumfile=$(getSumFileName $imagefile) # if [ ${#sumfile} != 64 ]; then # check to see if there are any outlying .fit file names # echo $imagefile # fi if [ -e /project/nearsdc/data/$sumfile ]; then echo $imagefile $sumfile fi done < msiImageList.txt