解析一个字符串,然后将它存储在一个数组中,然后在 shell 脚本上再次解析它

Parsing a string and then storing it an array and parsing it again on shell script

我是 shell 脚本编写的新手,需要帮助拆分字符串

STR="Hello this is Whosebug Hello I am asking about Whosebug"

所以基本上我想在有单词的时候拆分字符串 "Whosebug" 比如

Line 1: Hello this is Whosebug
Line 2: Hello I am asking about Whosebug

基本上我想在这里拆分一个字符串?有人可以帮忙吗

您可以使用 sed 将 Whosebug 和一个 space 替换为 Whosebug 和换行符:

echo "$STR" | sed -e "s/Whosebug /Whosebug\n/"