Hi I have created two arrays:
$ echo "${prot}"
abc
def
ghi
$ echo "${pos}"
123
456
789
where element n in prot refers to element n in pos. so I want to print the corresponding elements on one line, with one new line per pair.
I am trying to do this with a nested loop, where I split the respective arrays into elements via a newline:
for i in "${!prot[@]}"; do
for j in "${!pos[@]}"; do
IFS=$'\n' read -a arr1 <<<"$i"
IFS=$'\n' read -a arr2 <<<"$j"
echo $i $j
done
done
but this only gives me the last pair. it's one line which is great, but it's not printing them all. what am I doing wrong?
Expected output:
$
abc 123
def 456
ghi 789
I created the arrays in the first place by doing
for i in *.fasta; do
IFS=_-. read -ra arr <<<"$i"
tmp=$(printf "${arr[*]: 0: 1} ${arr[*]: 1: 1} ${arr[*]: -2: 1}")
fa+="$tmp\n"
done
for i in "${fa[@]}"; do
prot=$(echo -e "$i" | cut -d\ -f 1)
pos=$(echo -e "$i" | cut -d\ -f 2)
done