Простое решение, использующее функции оболочки Bash (видел a /bash
тег в вопросе):
con=" * ****** *** ** * **"
prot="M-ASDFRMKAWRGMLMI----WSGRCYYYYHQFLIMASDFRMKAMKAWWSGRCYNSHPPAAQVFYWLGLLSDVAGSALEAQ"
i=0
# Iterate until the index is less than the con string length
while [ $i -lt ${#con} ]
do
# Get the current element of the con "character array"
c=${con:$i:1}
if [[ $c == '*' ]]
then
# Get the corresponding element from the prot character array
p=${prot:$i:1}
echo $i, $c, $p
fi
i=$((i+1))
done
Вывод:
24, *, R
28, *, Y
29, *, Y
30, *, H
31, *, Q
32, *, F
33, *, L
41, *, M
42, *, K
43, *, A
45, *, K
46, *, A
48, *, W
67, *, G
68, *, L
Конечно, можно измениться echo
оператор для управления, что печатается.
В bash
пока нет многомерных массивов. Только ksh93
делает.
Здесь вы можете использовать структуру, подобную csv, и вам даже не нужно использовать массивы:
#! /bin/sh -
gws="\
foo,1.1.1.12,1::1
blah,2.2.2.2,2::2"
while IFS=, read name ip4 ip6; do
echo something with "$name" "$ip4"...
done << E
$gws
E
(вам даже не нужен bash)
С ksh93
:
gws=(
(name=foo ip4=1.1.1.1 ip6=1::1)
(name=blah ip4=2.2.2.2 ip6=1::2)
)
printf '%s\n' "${gws[0].name}"