shell

Hello,
I have the files(#600) like as..

0001.dcm
0002.dcm
0003.dcm
............
..........
0600.dcm

I would like to move these files to two different folder, say "a" and "b" folders. I want to make that the first five dcm files(0001.dcm, 0002.dcm, .... 0005.dcm) is moved to "a" folder, the second five dcm files(0006.dcm, 0007.dcm....0010.dcm) is move to "b" folder. I want to move the third five dcm file to the "a" folder again.

"a" folder has 0001.dcm, 0002.dcm, 0003.dcm, 0004.dcm, 0005.dcm, 0011.dcm, 0012.dcm, ...... 0595.dcm

"b" folder has 0006.dcm, 0007.dcm, 0008.dcm, 0009.dcm, 0010.dcm, 0016.dcm, 0017.dcm, ...... 0600.dcm

How can I do this? any suggestion?
Thanks in advance.
____________________________________________________________

Here is my code so far, but it does not work.....

k=5
kk=0

for f in *.dcm; do

  if ["$kk" -eq 0] && ["$(expr $(echo 0$f | tr -cd 0-9))" -le "$k" ]; then
        mv $f a
    else
      let "kk"=1
      let "k +=5"
    fi


  if ["$kk" -eq 1] && ["$(expr $(echo 0$f | tr -cd 0-9))" -le "$k" ]; then
        mv $f b
    else
      let "kk"=0
      let "k +=5"

    fi

done

assumes directory A and b both exist. try this:

#!/bin/bash
cd /path/to/dcm_files
for i in *.dcm
do
    num=${i%%.*}
    num=$(( $num % 10 ))
    if [ $num -lt 6 ]; then
        echo "test: moving $i to /path/to/a/${i}"   # comment out this line after testing
   #    mv $i  /path/to/a/${i}   #uncomment after you TEST this
    else
         echo "test: moving $i to /path/to/b/${i}"   # comment out this line after testing
   #    mv $i /path/to/b/${i}   # uncomment after you TEST this
     fi
done
test: moving 0001.dcm to /path/to/a/0001.dcm
test: moving 0002.dcm to /path/to/a/0002.dcm
test: moving 0003.dcm to /path/to/a/0003.dcm
test: moving 0004.dcm to /path/to/a/0004.dcm
test: moving 0005.dcm to /path/to/a/0005.dcm
test: moving 0011.dcm to /path/to/b/0011.dcm
test: moving 0012.dcm to /path/to/a/0012.dcm
test: moving 0013.dcm to /path/to/a/0013.dcm
test: moving 0014.dcm to /path/to/a/0014.dcm
test: moving 0015.dcm to /path/to/a/0015.dcm
test: moving 0021.dcm to /path/to/b/0021.dcm
test: moving 0022.dcm to /path/to/b/0022.dcm
test: moving 0023.dcm to /path/to/b/0023.dcm
test: moving 0024.dcm to /path/to/a/0024.dcm
test: moving 0025.dcm to /path/to/a/0025.dcm
test: moving 0031.dcm to /path/to/a/0031.dcm
test: moving 0032.dcm to /path/to/b/0032.dcm
test: moving 0033.dcm to /path/to/b/0033.dcm
test: moving 0034.dcm to /path/to/b/0034.dcm
test: moving 0035.dcm to /path/to/b/0035.dcm
test: moving 0041.dcm to /path/to/a/0041.dcm
test: moving 0042.dcm to /path/to/a/0042.dcm
test: moving 0043.dcm to /path/to/a/0043.dcm
test: moving 0044.dcm to /path/to/b/0044.dcm
test: moving 0045.dcm to /path/to/b/0045.dcm
test: moving 0046.dcm to /path/to/b/0046.dcm
test: moving 0047.dcm to /path/to/b/0047.dcm
test.sh: line 6: 0048: value too great for base (error token is "0048")

----------------------------------------------------------------------------------------------------------------------------------------------------

n=0
cur=a
ls | sort -t"." -n | while read file;do
if [ -f $file ];then
	n=$(($n+1))
	t=`echo $n % 5 | bc`
	mv $file $cur
	if [ $t -eq 0 ];then
		if [ $cur == 'a' ];then
			cur=b
		else
			cur=a
		fi
	fi
fi
done

Thanks so much, it works very well.