Using awk:
awk -F'-$' '{ printf "%s", sep $1; sep=/-$/?"":OFS } END{ print "" }' infile
with the -F'-$', we defined the Field Separator to single hyphen at the end of line, so with this and by taking the first field $1, we will always have the line without that hyphen for those line having this hyphen or still entire line for those not having that hyphen.
then we do simply printing it with a sep in between but that changes when reading the next line to empty-string if current line was ending with a hyphen otherwise to OFS (Output Field Separator, default is Space character).
at the END{...} block we are adding a final newline character to make it a POSIX text file, if you don't want that to be added, just remove that part.
Using sed, alternatively:
sed ':loop /-$/N;s/-\n//;t loop; N;s/\n/ /;t loop' infile
- :loop
- if a line ended with a hyphen (testing with
/-$/), do read the Next line and replace the "hyphen+\newline" with an empty string.
if substitution was successful (testing witht), then jump to the label loop and process the next line and skip executing rest of the code. - else, read the Next line and removereplace the embedded
\newline in between those two lines with a space character.
if substitution here was also successful, then jump to the label loop and process the next line.
- if a line ended with a hyphen (testing with