I am trying to use sed to remove all newline characters between two search patterns.
I first found this post which taught me how to search between two patterns across lines.
sed -e '/begin/,/end/{s/begin/replacement/p;d}'
Then I found this post to help remove all newlines in a file.
sed ':a;N;$!ba;s/\n/ /g'
I have attempted to combine the two answers and came up with:
sed -e '/begin/,/end/{:a;N;$!ba;s/\n/ /p;d}'
However, it doesn't quite work. It replaces newlines starting from the correct line, but continues until the end of the file. An example is given below:
Sed Command:
sed -e '/Seven/,/Fifteen/{:a;N;$!ba;s/\n/ /g}' input.txt
input.txt:
One Two Three
Four Five Six
Seven Eight Nine
Ten Eleven Twelve
Thirteen Fourteen Fifteen
Sixteen Seventeen Eighteen
Nineteen Twenty Twenty-One
Output:
One Two Three
Four Five Six
Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen Nineteen Twenty Twenty-One
What I really want:
One Two Three
Four Five Six
Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen
Sixteen Seventeen Eighteen
Nineteen Twenty Twenty-One
Thanks for any help!