2
1
I have an RTF file which is formatted like so:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.\par
Nullam vitae sem porttitor urna pellentesque gravida. Nulla\par
consequat purus vel est vehicula porttitor.\par
Maecenas pharetra metus in enim sollicitudin sollicitudin.\par
Etiam et odio tellus, eget placerat enim. Aliquam sem purus,\par
gravida sed feugiat eget, consectetur quis nisl.\par
(\par added for brevity)
As you can see, newlines have been inserted to fit a page's width. The problem arises when I try to read the text on my iPhone, which has a different line length. The lines break and readability is hindered.
The ideal solution would be one that converts the file to a single line for each paragraph, while keeping the newline and indent for new paragraphs.
So far I've tried parsing the file with sed but was unable to create a multiline regex. Ideally, I want to replace all "\r\n"s with " ", unless the next line begins with a space.
Is there a better solution for this? If not, how can I do it using sed?
sed works by reading one line at a time. \r\n doesn't match – MoshiBin – 2009-07-28T21:24:20.503
Hmm, then use a tool that works on the whole file at once then – Peter Boughton – 2009-07-28T21:25:41.640
Or here's a possible solution for doing multi-line with sed: http://www.ilfilosofo.com/blog/2008/04/26/sed-multi-line-search-and-replace/
– Peter Boughton – 2009-07-28T21:27:43.710