Any attempts / ideas / thoughts from your side? With more than 900 posts in these forums we'd suppose you had at least a faint vision of the way to go...?
With over 900 posts, you know the standard questions for every thread in this forum...
What operating system are you using?
What shell are you using?
What have you tried to solve this problem on your own?
And a few more questions related to this thread...
Are all of the files to be moved located in a single directory?
If not, in what directories are they located?
When you say you have a large number of files, are there so many that if you run the commands year=2018 , day=030 , and then ls -1 *.d.$year.$day.*.sac that you get an error from your shell saying something like " argument list too long "? Note that you should try this with year and day values for the day with the largest number of files you'll need to process.
fnames=`ls *.sac`
for f in $fnames; do
day=`echo "$f" | grep -oP 'd+.[\d]+.[\d]+'`
echo "file: $f"
echo "day: $day"
ftyp=`echo "${f:0:3}"`
# Do not remake directory if it already exists
# Skip pzs files
if [[ ! -e $day ]] && [ $ftyp != "pzs" ]; then
mkdir $day
echo "Created directory $day"
elif [[ ! -d $day ]]; then
echo "$dir already exists but is not a directory"
fi
# Copies file to station directory
if [ $ftyp != "pzs" ]; then
cp $f $day
else
echo "Detected pzs file"
fi
echo ""
done
Note that if you would change the code marked in red above to the following:
for f in *.sac; do
... ... ...
ftyp=${f:0:3}
your code would use fewer system resources, run faster, and produce exactly the same results.
We could probably make several other suggestions that might help you improve the performance of your script. But since you refuse to tell us what operating system and shell you're using, there is no reason for us to waste our time making guesses that might not work in your environment.