The problem seems to boil down to:
"Find all files with the pattern '[something]_data.csv' and report if '[something]_A.csv' doesn't exist"
Unless I'm missing something, all the sorting and sequence generation isn't adding anything.
$ printf '%d\n' "0005" 5
$ printf '%d\n' "0025" 21
$ echo "0005" | xargs printf '%d\n' 5
The problem seems to boil down to:
"Find all files with the pattern '[something]_data.csv' and report if '[something]_A.csv' doesn't exist"
Unless I'm missing something, all the sorting and sequence generation isn't adding anything.