I am trying to a) count how many files I have on my mass filer EMC device, b) load them in an array c) display a count of how many files I have d) bulk load each file in my database e) display the name of the file I just loaded.
This is my code...
export OUT=/path/to/device
P_Array=$(cd ${OUT} ; find . -name "*TXT" | wc -l)
Plen=${#P_Array[@]}
echo "$Plen FILES TO PROCESS."
if [ $Plen -eq 0 ]
then
echo "`date '+%m/%d/%y %T:'` ZERO FILES."
fi
for name in ${P_Array[@]}
do
###Database Bulk Load Here###
echo "`date '+%m/%d/%y %T:'` $name was loaded."
done
Problem A: Plen=${#P_Array[@]} displays a count of 1 when it should be 5 (sandbox env, right now).
Problem B: $name display the total number of files instead of the individual file name.
Obviously, this is all wrong. I am sure I have something switched around but I am not sure what it is. Help!
Since you do wc -l on the result of find it's going to give the number of files. Hence, the P_Array contains only one number. So Plen is just 1.
Change them to:
P_Array=$(cd ${OUT} ; find . -name "*TXT")
Plen=$(cd ${OUT} ; find . -name "*TXT" | wc -l)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With