The bash below goes to a folder and stores all the unique values that are .html file names in f1. It then removes all text after the _ in $p. I added a for loop to get the unique id in $p. The terminal out shows $p is correct, but the last value is only being stored in the new array ($sorted_unique_ids), I am not sure why all three are not.
dir=/path/to
var=$(ls -td "$dir"/*/ | head -1) ## sore newest <run> in var
for f1 in "$var"/qc/*.html ; do
# Grab file prefix
bname=`basename $f1` # strip of path
p="$(echo $bname|cut -d_ -f1)"
typeset -A myarray ## define associative array
myarray[${p}]=yes ## store p in myarray
for i in ${!myarray[@]}; do echo ${!myarray[@]} | tr ' ' '\n' | sort; done
done
output
id1
id1
id1
id2
id1
id2
id1
id2
id3
id1
id2
id3
desired sorted_unique_ids
id1
id2
id3
"$p"?"${id[@]}"with the same result. Thank you :).$pis not an array here, neither is$id, so it makes no sense to use the${var[@]}syntax."$var"/qc/id1_blabla.html"$var"/qc/id2_blabla.html"$var"/qc/id3_blabla.html? And you want to get the list of ids? Then why do you runfor i in ${!myarray[@]}for each file?done; right now you're getting repeated lines on output because you are, basically, printing eachpvalue to stdout as you process it ... where what you want to do is wait until you've completed all loop processing, completed all array assignments, and then you should find that you have a unique set ofpvalues stored in the array