You might be asking a bit much of the shell to get the location number this way. Try using sed...
Code:
fileName=str0002.asc.23154
locationNumber=$(echo $(basename ${fileName}) | sed 's/^.*\([0-9]\{4\}\)\..*/\1/')
To test if file exists use 'test -f fileName' or 'test -e fileName'.
HTH