如何使用awk将两个模式之间的未知数量的多行合并为一行

use*_*393 2 shell awk grep

我有一些文本文件,其中每个文件将有如下信息

235.91 245.67 B: some information here
246.79 246.99 A: some other information here,
more information here,
and may be here
247.45 248.99 A: some other text here,
some more here
249.98 ---- 
Run Code Online (Sandbox Code Playgroud)

并且模式重复

我希望文本安排如下:

235.91 245.67 B: some information here
246.79 246.99 A: some other information here, more information here, and may be here
247.45 248.99 A: some other text here. some more here
249.98 -----
Run Code Online (Sandbox Code Playgroud)

这意味着我想合并两个匹配模式之间的所有行(它们之间有空格)

我希望每一行都以数字作为模式开始.数字始终有一个小数点,小数点后有两位数.图案与下一个图案之间的线数不同(可以有一条或多条线或根本没有线).

有人可以使用shell脚本帮助我这样做,最好使用awk吗?

Ed *_*ton 7

听起来你需要这样的东西:

awk '
{ printf "%s%s", ($1 ~ /\.[[:digit:]][[:digit:]]/ ? rs : FS), $0; rs=RS }
END { print "" }
' file
Run Code Online (Sandbox Code Playgroud)