I'm trying to create a for loop in bash which uses two different files (with same prefix). For example:
/home/samples - Contains files A.fq B.fq etc
/home/annotation - Contains files A.tab B.tab etc
I call their names in two separate arrays:
filepathsfq=( /home/samples/*fq )
filepathstab=( /home/anottation/*tab )
Now I want to call in a command
paste "${filepathsfq[@]##*/}" "${filepathstab[@]##*/}"
Such that I get, in a loop:
A.fq A.tab
B.fq B.tab
In my speficic case, the first 10 characters of each prefix should be equal!
I tried to create pairs in arrays without much success (with declare command)
such as:
samples=("${filepathsfq[@]##*/}")
declare -A tabs=("${filepathsrtab[@]##*/}")
for sample in "${samples[@]}"; do
echo "$sample is the same as > ${tabs[$sample]}"
done
Of course this one above does not check for matching prefixes and would not work properly if some file does not contain a proper pair.
I've tried readarray without success because my first code
filepathsfq=( /home/samples/*fq )
Is already an array and I can't redirect it to readarray