Bash 通过多字符分隔符将多行字符串拆分为数组

Hub*_*bbs 3 bash shell awk

我在这里搜索了类似的主题,但大多数问题都包含单字符分隔符。

我有这个文本样本:

Some text here,
continuing on next lineDELIMITERSecond chunk of text
which may as well continue on next lineDELIMITERFinal chunk
Run Code Online (Sandbox Code Playgroud)

所需的输出是一个列表 ( extracted=()),其中包含:

  1. Some text here, continuing on next line
  2. Second chunk of text which may as well continue on next line
  3. Final chunk

从示例中可以看出,“DELIMITER”用作分割分隔符。

我在 SO 上尝试了许多示例,包括 awk、替换等。

Rav*_*h13 5

如果您不想更改默认RS值,请尝试以下操作。

awk '{gsub("DELIMITER",ORS)} 1' Input_file
Run Code Online (Sandbox Code Playgroud)