I am trying to find and process all files with a given ending (.txt in the example below) in a directory. My current example finds all files containing .txt anywhere in the file name (e.g. also files with the ending .txt*, e.g. .txt.xls).
DATADIR=$1
for DATA in `ls $DATADIR`; do
DATABASENAME=$(basename $DATA)
echo "Basename of file $DATABASENAME"
if [[ ${DATABASENAME} =~ .*txt ]];
then
DATAPATH="$DATADIR$DATABASENAME"
echo "File path $DATAPATH"
fi
done