#!/usr/bin/env bash # Separate TADARIDA nights into corresponding folders # Specify starting and ending hours for fixed point protocol START_TIME="22:00" END_TIME="06:01" # add 1 minute to include exceeding records # Specify records source and destination directories SOURCE_DIR="/run/media/ortion/Teensy" DESTINATION_DIR="/run/media/ortion/55E981D167764F75/Documents/nature/media/protocoles/vigie-chiro/pt_fixe/490982/Pass0" # Function that separates records of each nights using regex function separate_nights() { START_TIME=$(echo $1 | sed 's/:/ /g') END_TIME=$(echo $2 | sed 's/:/ /g') SOURCE_DIR=$3 DESTINATION_DIR=$4 # Get list of files in source directory FILES=$(ls $SOURCE_DIR/*.wav) current_date="" current_dir="" for FILE in $FILES; do # Get date of record DATE=$(echo $FILE | cut -d'_' -f2) # Get hour of record HOUR=$(echo $FILE | cut -d'_' -f3 | cut -d'.' -f1) # Copy record in proper directory # If time is in night range, copy record in destination directory into the current night directory if [ "$TIME" -ge "$START_TIME" ] && [ "$TIME" -le "$END_TIME" ]; then # If current dir is not yet specified create a directory according to the current date if [ "$current_dir" == "" ]; then current_dir=$(echo $DATE | cut -b 1-4,5-6,7-8 --output-delimiter="-") mkdir -p "$current_dir/raw" echo "New night !" echo "Created directory $current_dir." fi cp "$FILE" "$DESTINATION_DIR/$current_dir/raw/" else current_dir="" fi done } separate_nights "$START_TIME" "$END_TIME" "$SOURCE_DIR" "$DESTINATION_DIR"