Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 1185  / 2 Years ago, thu, february 10, 2022, 5:27:40

Here is what I have



This
is
a
sample
text

How
to
do
it
?


I need the output to be:




This is a sample text
How to do it ?


In addition, how can I achieve the same with:



This
is
a
sample
text
How
to
do
it
?


How to append lines starting with non upper case characters to be appended each to previous line?


More From » text-editor

 Answers
4
sed -r ':a;N;$!ba;s/
([^A-Z])/ 1/g'


:a create a label b



N Search all the lines mashed together instead of searching line by line



$! if not the last line, b branch (go to) label a (skip the last line because the last line has a final newline)



s substitution




([^A-Z])
match a newline followed by anything not a capitalized letter. The ( and ) group together the anything not a capitalized letter.



/ 1/' replace our match with a space followed by group 1



g copy the hold buffer contents to the pattern space



Credit belongs here and here and here.


[#32300] Friday, February 11, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nuehan

Total Points: 253
Total Questions: 109
Total Answers: 120

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
nuehan questions
Sun, Dec 18, 22, 17:34, 1 Year ago
Mon, Mar 28, 22, 00:10, 2 Years ago
Fri, Jun 24, 22, 11:39, 2 Years ago
Thu, Apr 28, 22, 20:54, 2 Years ago
Fri, Aug 20, 21, 01:06, 3 Years ago
;