I know you have solved your initial issue but I thought I would give a little feedback on what you have as it confused me
a little.
Quote:
#CREATE ARRAY OF GROUPED FILES
|
Whilst I understand what you have said here, strictly speaking you only created a single string with:
Code:
FILES=$( ls $DIR_PATH/*.$EXT | xargs -n1 basename )
Yes it will act like an array in a for loop because word splitting takes affect and the spaces used as delimeters.
Also the assumption here is no file names have spaces.
To actually be an array you need another set of parenthesis, like so:
Code:
FILES=($( ls $DIR_PATH/*.$EXT | xargs -n1 basename ))
I mention this as then you would be able to use array properties in the next line:
Code:
FILE_COUNT=$( echo $FILES | wc -w )
#becomes
FILE_COUNT=${#FILES[*]}
The following assumes not dots anywhere else in filename:
Code:
prefix=$( echo $FILE | cut -d '.' -f1 ); #this correctly gets everything up to first '.'
As you already have the extension stored in EXT you could use substituion:
Code:
prefix=${FILE%.$EXT}
Lastly, the following line concerns me:
Code:
FILES=$( echo "${FILES}" | grep -Ev "${prefix}*\.${EXT}" );
The reason it concerns me is because changing the values of what you are iterating over could come unstuck and cause
the rest of the program to be very wrong (just a thought)