File size: 1,321 Bytes
15487d0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
#!/bin/bash
set -eo pipefail
if [ "$#" -lt 2 ]; then
echo "Format: $0 <input_folder> <size> [reset_indices]"
exit 1
fi
unset reset_list reset_files_list reset_files_num
declare -a reset_list
declare -a reset_files_list
reset_files_num=0
if [ "$#" -eq 3 ]; then
IFS="," read -r -a reset_list <<< $3
while IFS= read -d $'\0' -r f; do
reset_files_list[reset_files_num++]="$f"
done < <(find $1 -type f -iname "*short*.wav" -print0 | sort -V -z)
if [ $reset_files_num -eq 0 ]; then
echo "No reset files found in directory $1"
exit 1
fi
fi
if [ ! -d "$1" ]; then
echo "First argument should be a directory (got $1)"
exit 1
fi
unset list i
i=0
declare -a list
while IFS= read -d $'\0' -r f; do
list[i++]="$f"
done < <(find $1 -type f -iname "*.wav" ! -iname "*short*" -print0 | sort -V -z)
if [ $i -le 0 ]; then
echo "No files found in directory $1"
exit 1
fi
LIMIT=$2
case $LIMIT in
*[!0-9]*) echo "Second argument should be a positive number (was $2)"; exit 1;
esac
LIMIT=$((LIMIT-1))
OUT=""
for index in $(seq 0 $LIMIT)
do
val=$((index%i))
if [[ " ${reset_list[@]} " =~ " $index " ]]; then
rval=$((index%reset_files_num))
OUT="$OUT ${reset_files_list[$rval]};${list[$val]}"
else
OUT="$OUT ${list[$val]}"
fi
done
echo $OUT
|