I have a small script.
#!/bin/bash
# test for regular expressions to match...
DIR="/search/path/"
NAME="FOO[0-9][0-9]_<bar|dog|cat>"
for FILE in `find ${DIR} -maxdepth 1 -type f -name "*\.[dD][oO][cC]"`
do
BASENAME=`basename ${FILE}`
FILENAME="${BASENAME%.*}"
if [[ "${FILENAME}" == ${NAME} ]]
then
echo "Found $FILENAME"
else
echo "$FILENAME not matching..!"
fi
done
In this script I want to match all files that start with FOO[0-9[0-9]_
and then either bar
, dog
, or cat
. But if something else is there like bog
or cog
or car
it should NOT match.
When I do [a-z][a-z][a-z]
they will match...
I already tried doing something like:
NAME="FOO[0-9][0-9]_(bar|dog|cat)"
or
NAME="FOO[0-9][0-9]_bar|dog|cat"
or
NAME="FOO[0-9][0-9]_[bar|dog|cat]"
or
NAME="FOO[0-9][0-9]_'bar|dog|cat'"
But in the documentation about regular expressions I could not find an exact match.
I need to have it in a single line, as the main script I use it for is a lot more complex and have a lot of different sub processes hanging off of it.
Is this even possible...?