bash - unix shell scripting for moving files sequentially with file names as fixed increment into directories -


i have large number of directories increments of time step 0.00125. want copy time directories 8 directories sequentially i.e algorithm can think of is

delta_time = 0.00125     if directory_name = 0.00125 mv 0.00125/ main_dir1     if directory_name = 0.0025  mv 0.00250/ main_dir2     if directory_name = 0.00375 mv 0.00375/ main_dir3     .     .     .     if directory_name = 0.01    mv 0.01/ main_dir8     if directory_name = 0.01125 mv 0.01125/ main_dir1 (again)     if directory_name = 0.0125  mv 0.0125/  main_dir2          .     .     .     .     if directory_name = 0.02    mv 0.02/ main_dir8     .     .     on    

the time directories large in number (around 200 directories) im thinking of writing bash script. im relatively new bash scripting still cant think of logic this!

you want modular arithmetic on directory names, exception multiples of 8 want use 8 instead of 0. so:

#!/bin/sh  increment="0.00125" maxdir=8 directory_name in 0.*     if [ -d "$directory_name" ]             target_dir_num=$(echo "($directory_name / $increment) % $maxdir" | bc)         if [ $target_dir_num -eq 0 ]                     target_dir_num=$maxdir         fi          echo mv $directory_name main_dir${target_dir_num}     fi  done  

should trick.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -