Using sed
and 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.
The sed script inserts a newline before every line that begins with a capital letter (except for the very first line of input). sed
's output is then piped into fmt
to reformat the resulting paragraphs.
Alternatively use par
if you have it installed. It's another paragraph reformatter, but much more capable than fmt
, with many more features and options.
Note that there will be a blank line between each paragraph. Paragraphs should be separated from each other by at least one blank line.
Without the blank lines, your entire input sample is reformatted as a single multi-sentence paragraph, e.g.:
$ fmt input.txt
This is one sentence that is broken. However this is a good one.
And this one is somehow, broken into many.
If you need to remove the blank lines after reformatting just pipe it through sed
again - but this will remove ALL blank lines, including any that may have been in the original input. e.g.
$ 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.