I'm working in CentOS with bash and I have files in a directory as follows:
16948.png
16948_thumb.png
16948-1_thumb.png
16949.png
16948_thumb.png
16949-1_thumb.png
16950-1.png
16950-1_thumb.png
16950-2.png
16950-2_thumb.png
I would like to do the following:
- For each unique number N that exists in the list of files:
- check that there is a file N-1.png:
- if not, create it by copying N.png to N-1.png (there will always be an N.png)
- delete the file N.png
- check that there is a file N-1_thumb.png:
- if not, create it by copying N_thumb.png to N-1_thumb.png (there will always be an N_thumb.png)
- delete the file N_thumb.png.
However, my shell scripting isn't good enough to come close to this. This is as far as I've got - can anyone help?
#!/bin/sh
declare -a unique_numbers
for filename in ./images
do
// split filename at - or _ to get N, and then check
// whether N is already in list of unique numbers
// if it is, skip
continue
// if it isn't, append to unique_numbers
unique_numbers+=(N)
// then check whether there is a file N-1.png.. etc
done;