#!/bin/bash   # FILE COPIER SCRIPT / FILELOCATOR # usage: filelocator [location number file] [destination] [optional location number length, default 4] # # ex: ./filelocator classic-locations.txt /cygdrive/c/test2/ 5 #   #IFS=' #' oIFS=$IFS IFS=$'\n' stty cols 100   #location number length – Default 4 loc_length=${3:-4}   # Count lines in file total_lines=$(wc -l < $1) total_lines=$((total_lines+1)) count=1   #clear screen printf "\033c" tput civis tput cup 0 0 echo -e "####################################################################################################" echo -e "##############################\e[40m\e[1m FILE COPIER - Sandrew Metronome \e[0m#####################################" echo -e "####################################################################################################" echo -e "\e[93m" echo -e "Location number file:\e[92m $1" echo -e "\e[93mNumber of lines: \e[92m"$total_lines echo "" echo -e "\e[93mFile destination:\e[92m $2" echo -e "\e[93m" sleep 2   #clear log on run destination=$2 #second argument is file destination rm $destination/log/*   print_percent() {  str=$1  num=$2  v=$(printf "%-${num}s" "$str")  echo -e "\e[104m""${v// /#}""\e[0m"\\r }   full_percent() {  str=$1  num=$2  v=$(printf "%-${num}s" "$str")  echo -en "\e[41m""${v// /#}""\e[0m"\\r }   tput cup 14 0 full_percent "#" 100   while read line || [ -n "$line" ]; #read each line from the file in the first argument do     name=$line;     folder=${line:0:$loc_length} #folder name is first four digits of location number     track=${line: -2} #track identifier is last two digits of location number     folderlocation="$(locate -r '/'$folder'$' )" #search database for folder name, returns full path     filelocation="$(find "$folderlocation" -type f -name "$track*wav" 2>/dev/null)" #find specific track inside folder location using track number.         # Create folders in destination – All error messages suppressed     mkdir $destination/"$folder"/ 2>> /dev/null     mkdir $destination/"$folder"/album 2>> /dev/null     mkdir $destination/log  2>/dev/null         # Give feedback on process     tput cup 9 0     echo -e "\e[93mCopying Folder: \e[96m$folder\e[0m, \e[93mTrack: \e[96m$track \e[21m\e[39m\e[0m"       #print current line out of total lines     echo -e "\e[93m"Current: "\e[92m"$count "\e[93m/" "\e[92m"$total_lines     echo -e "\e[93mFiles left: \e[92m" $(($total_lines-$count))     echo -e "\e[0m"     percent=$(printf '%i %i' $count $total_lines | awk '{ pc=100*$1/$2; i=int(pc); print (pc-i<0.5)?i:i+1 }')     echo $percent"%"     print_percent "#" $percent     tput rc         (( count++ ))         # Copy file found earlier to specified destination     cp -ri "$filelocation" $destination/"$folder"/album/ 2>>$destination/log/"$folder"-"$track"         # Delete all log-files that are 0 bytes (non-errors)     find $destination/log/ -name '*' -size 0 -print0 | xargs -0 rm 2>/dev/null     done < $1 tput cup 15 0 tput cnorm files_logged=$(find $destination/log/ -type f | wc -l) echo -e "FILE OPERATION COMPLETED!\e[93m " $files_logged "files logged!" echo -e "LOG LIST: \e[95m" echo $(find $destination/log -type f -printf "%f\n")   #rename log files to .txt   for f in $destination/log/*; do     mv -- "$f" "${f%}.txt" 2>/dev/null done   print_logs() { echo -e "\e[93m" read -p "Do you want to see log files printed? " answer case ${answer:0:1} in     y|Y|yes|Yes )         echo -e "\e[96m"         for f in /cygdrive/c/test2/log/*; do cat $f; echo -e "\n";done     ;;     * )         exit     ;; esac }   if [ $files_logged -gt 0 ]; then         print_logs() fi