I have a script that downloads image zips and extracts them. The images are in the format:
01234567_00.jpg
01234567_01.jpg
01234567_02.jpg
01234568_00.jpg
You get the idea. I need to move all the images to a directory by the last number
before the underscore.
For instance,
01234567_00.jpg moves to the ln7 directory
01234563_00.jpg moves to the ln3 directory
Here is what I have so far to take the images and move them one at a time to their appropriate directories:
Code:
find *.jpg | while read FILE;
do
dir=${FILE:7:1}
# echo $FILE - $dir
mv -f $FILE work/ln$dir/
# echo Moved $FILE to ./work/ln$dir/$FILE
done
I get "Argument list too long" when I try to run the command. There are several thousand images in the directory.
Can I use xargs in a shell script like that?
I'm new to shell scripting - any help would be greatly appreciated.