使用sed
和fmt
:
$ sed -e '1n; s/^[[:upper:]]/\n&/' input.txt | fmt
This is one sentence that is broken.
However this is a good one.
And this one is somehow, broken into many.
sed脚本在以大写字母开头的每一行之前插入换行符(输入的第一行除外)。 sed
然后将的输出通过管道fmt
传递给重新格式化结果的段落。
par
如果已安装,也可以使用。这是另一段重新格式化的程序,但功能比强大得多fmt
,具有更多的功能和选项。
请注意,每个段落之间将有一个空白行。段落之间应至少用一个空白行隔开。没有空白行,您的整个输入样本将重新格式化为单个多句段,例如:
$ fmt input.txt
This is one sentence that is broken. However this is a good one.
And this one is somehow, broken into many.
如果您需要在重新格式化后删除空白行,只需sed
再次将其通过管道传输-但这将删除所有空白行,包括原始输入中可能包含的所有空白行。例如
$ sed -e '1n; s/^[[:upper:]]/\n&/' input.txt | fmt | sed -e '/^$/d'
This is one sentence that is broken.
However this is a good one.
And this one is somehow, broken into many.