Transferring files to directories

I have a large number of files with file names of the format

iv.epoz.hhe.d.2018.028.000000.sac
iv.epoz.hhn.d.2018.028.000000.sac
iv.epoz.hhz.d.2018.028.000000.sac
iv.epoz.hhe.d.2018.029.000000.sac
iv.epoz.hhn.d.2018.029.000000.sac
iv.epoz.hhz.d.2018.029.000000.sac
mn.clta.hhe.d.2018.030.000000.sac
mn.clta.hhn.d.2018.030.000000.sac
mn.clta.hhz.d.2018.030.000000.sac
etc

The file names are set up such that d.2018.030 is the 30th day of 2018

I want to have a folder of each day in the format d.year.day such
as for example d.2018.028 and transfer the files there. And so on
for each day.

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...?

Expanding on what RudiC has already said...

With over 900 posts, you know the standard questions for every thread in this forum...

  1. What operating system are you using?
  2. What shell are you using?
  3. What have you tried to solve this problem on your own?

And a few more questions related to this thread...

  1. Are all of the files to be moved located in a single directory?
  2. If not, in what directories are they located?
  3. 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

Have done something as above. Seems to work

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.