Assumptions:
- all 6-digit strings are of the format
xx[03]0000
(ie, has to be an even 00
or 30
minutes and no seconds)
- if there are strings like
xx1529
... these will be ignored (see 2nd half of answer - use of comm
- to address OP's comment about these types of strings being an error)
Instead of trying to do a bunch of mod 60
math for the MM
(minutes) portion of the string, we can use a sequence generator to generate all the desired strings:
$ for string_check in {00..23}{00,30}00; do echo $string_check; done
000000
003000
010000
013000
... snip ...
230000
233000
While OP should be able to add this to the current code, I'm thinking we might go one step further and look at pre-parsing all of the filenames, pulling the 6-digit strings into an associative array (ie, the 6-digit strings act as the indexes), eg:
unset myarray
declare -A myarray
for file in ${file_list}
do
myarray[${file:22:6}]+=" ${file}" # in case multiple files have same 6-digit string
done
Using the sequence generator as the driver of our logic, we can pull this together like such:
for string_check in {00..23}{00,30}00
do
[[ -z "${myarray[${string_check}]}" ]] &&
echo "Problem: (file) '${string_check}' is missing"
done
NOTE: OP can decide if the process should finish checking all strings or if it should exit
on the first missing string (per OP's current code).
One idea for using comm
to compare the 2 lists of strings:
# display sequence generated strings that do not exist in the array:
comm -23 <(printf "%s\n" {00..23}{00,30}00) <(printf "%s\n" "${!myarray[@]}" | sort)
# OP has commented that strings not like 'xx[03]000]` should generate an error;
# display strings (extracted from file names) that do not exist in the sequence
comm -13 <(printf "%s\n" {00..23}{00,30}00) <(printf "%s\n" "${!myarray[@]}" | sort)
Where:
comm -23
- display only the lines from the first 'file' that do not exist in the second 'file' (ie, missing sequences of the format xx[03]000
)
comm -13
- display only the lines from the second 'file' that do not exist in the first 'file' (ie, filenames with strings not of the format xx[03]000
)
These lists could then be used as input to a loop, or passed to xargs
, for additional processing as needed; keeping in mind the comm -13
output will display the indices of the array, while the associated contents of the array will contain the name of the original file(s) from which the 6-digit string was derived.