Проблема в том, что вам нужно выполнять поиск итеративно, каждый раз удаляя первую совпавшую часть:
string="word1 word2 word3 word4 the word5 word6 word7 word8 word9 the quoi écrire hihi haha the a b c d e"
copy=$string
while m=$(grep -Eo '([^ ]+ ){4}the( [^ ]+){5}' <<<"$copy"); do
echo "$m" | head -1 # print just the first one
copy=${copy#* the } # remove up to and including the _first_ " the "
done
word1 word2 word3 word4 the word5 word6 word7 word8 word9
word6 word7 word8 word9 the quoi écrire hihi haha the
quoi écrire hihi haha the a b c d e
Или используйте встроенную в bash поддержку регулярных выражений, что означает, что вам не нужно анализировать какие-либо grep
выходные данные для вывода первого совпадения:
copy=$string
# the pattern is *unquoted*
while [[ $copy =~ ([^ ]+ ){4}the( [^ ]+){5} ]]; do
echo "${BASH_REMATCH[0]}"
copy=${copy#* the }
done
Я предполагаю, что вы используете Alpine, начиная с USB-ключа, даже если это не указано. Если это так, вы можете изменить файл /boot/syslinux.cfg
следующим образом:
serial 0 9600
timeout 20
prompt 1
default vanilla
label vanilla
kernel /boot/vanilla
append initrd=/boot/vanilla.gz alpine_dev=sda1:vfat modules=sd-mod,usb-storage console=ttyS0,9600
В зависимости от используемой версии Alpine некоторые записи могут отличаться. Соответствующие части, которые вы должны добавить, это :serial 0 9600
и добавьте console=ttyS0,9600
к записи append initrd=
.
Полные инструкции можно найти здесь:https://wiki.alpinelinux.org/wiki/Enable_Serial_Console_on_Boot
. :Франческо Колиста