首页 > 解决方案 > 如果下一行以单词字符开头,则用空格替换新行

问题描述

我有一个看起来像的大文本文件

some random : demo text for
illustration, can be long

and : some more

here is : another
one

我想要一个像这样的输出

some random : demo text for illustration, can be long
and : some more
here is : another one

我尝试了一些奇怪的,明显错误的正则表达式,%s/\w*\n/ /g但无法真正理解。

标签: awkunix-text-processing

解决方案


使用您显示的示例,请尝试以下awk代码。使用 RS(记录分隔符),将其设置为无效。这仅基于您显示的示例。

awk -v RS="" '{$1=$1} 1' Input_file

推荐阅读