I have a stupid problem. I've been trying to create a bash script for checking if a .tif file exists based on a path found in an auto generated .txt file. The problem, however, is that I can't get my code to echo out all the contents of my TIF_PATH array, it only shows the first entry found.
Example of .txt file:
INPUT_FILE_DOC_TIF=/home/user/documents/tif.tif
Any idea what I'm doing wrong? As you can see, I'm a big noob.
Thanks in advance.
count_recursive ()
{
command find "${1:-.}" -type f -name "${2:-*}" -print0 |
command tr -dc '\0' | command wc -c;
return 0
}
#FIND_TXT = Finds .txt files for the array.
FIND_TXT=$(find . -type f -name "*.txt")
Used for creating the array, and finding the auto generated .txt files.
#Save and change Internal Field Seperator (used to remove potential blank spaces, breaks and seperators)
OLDIFS=$IFS
IFS=$'\n'
#Read all file names into an array
declare -a FILE_ARRAY=($FIND_TXT)
#Restore it
IFS=$OLDIFS
#Get length of array
declare -a tLen=${#FILE_ARRAY[@]}
#Output path to a new variable, TIF_PATH, via egrep.
declare -a TIF_PATH=$(egrep "INPUT_FILE_DOC_TIF" "${FILE_ARRAY[$@]}" | sed 's#INPUT_FILE_DOC_TIF=##g')
#Output path without file name.
#declare -a PISS_PATH=$("${TIF_PATH}" | sed 's/..........$//')
#Use for loop to read all filenames
for (( i=0; i<${tLen}; i++ ));
do
echo "$i"
echo "${FILE_ARRAY[$i]}"
#Can be changed to output all, instead of increment.
echo "${TIF_PATH[$i]}"
#find . -type f -print | xargs grep ""
#echo "${PISS_PATH[$@]}"
#find . -type f -name "$TIF_PATH")
done
And the result:
./txt/asd.txt
/home/user/Documents/Scripts/tiffile.tif
1
./txt/1000001.txt
2
./txt/111100001.txt
3
./txt/0047-001124-000000001.txt
4
./test/0047-001124-000000001.txt
5
./0047-001124-000000001.txt
tLen=${#FILE_ARRAY[@]}