You don't need to use find, ls, grep, or globbing at all. Your use of grep is wrong anyway since grep uses regular expressions, not globbing -- "fileone*" matches "fileon", then one or more e's. and does so anywhere in the line, so "aaaaaafileon" would match "fileone*".
The shell has many operators for use inside [ ] which can be used to check files, directories, or variables in many ways, see man test.
# Today's date
DATE=$(date +%Y_%m_%d)
for X in fileone filetwo filethree
do
[ -f "${X}_${DATE}.dat" ] && echo "${X} exists"
done
thanks for your inputs. I will have only today'sfiles only, in other words everday the old files will be archived and only current day files will be present in that dir.
No. The code as I gave it is what I meant. No more, no less.
# Today's date
DATE=$(date +%Y_%m_%d)
for X in fileone filetwo filethree
do
[ -f "${X}_${DATE}.dat" ] && echo "${X} exists"
done
Your version won't work. * won't expand inside "", and if you remove the "", it will start complaining when * matches more than one file because -f doesn't take multiple files.
If you found a way to make it work, your error-checking code still wouldn't see any difference between files from previous days and files from the current day, making it fairly pointless.
YMD=$(date +%Y_%m_%d)
#
if [ -f "fileone_${YMD}.dat" -a -f "filetwo_${YMD}.dat" -a -f "filethree_${YMD}.dat" ]
then
echo "All three files exist
else
echo "One of more files is missing"
fi
If I read the question another way, the match on today's date doesn't matter.
filecount=$(ls -1d fileone_????_??_??.dat filetwo_????_??_??.dat filethree_????_??_??.dat 2>/dev/null | wc -l)
if [ $filecount -ne 3 ]
then
echo "one or more of the three files is missing"
fi