Page 1 of 1

Using Replace to remove line breaks

Posted: Mon Jan 14, 2019 10:54 pm
by Dr Spyn
I have a long text document with manual single line breaks I'd like to replace with a space. When I place \n in the Search For field and a space in the Replace With field, then click on Replace All, the message "Search Key Not Found" appears. Please reply with a verbose step-by-step explanation as I'm a nitwit.

Re: Using Replace to remove line breaks

Posted: Mon Jan 14, 2019 11:43 pm
by Zizi64
When I place \n in the Search For field and
The \n will search an find the Shift-Enter type line breaks only - if the Regular Expressions option is checked in the other options area of the dialog.
Please stusy the the Regular expressions in the HELP or on this page:
https://help.libreoffice.org/Common/Lis ... xpressions

Re: Using Replace to remove line breaks

Posted: Mon Jan 14, 2019 11:50 pm
by RoryOF
Turn on /View /Non printing characters.

Note the line ends - are they left pointing hooked arrows (line breaks) or backwards P characters (Pilcrows)? If the left arrows, enter \n in Find. If Pilcrows, enter $ in Find. In either case in Replace enter a single space.

Before clicking Replace All button, drop More Options on the F&R window and select "Regular Expressions". Now click Replace All.

Be advised that if your document is long - more than 64K characters (say about 10,000 words)- this is not a good thing to do, as OO hangs with paragraphs longer than 64K characters, often about 15 pages.

The non printing characters display does not print, and is turned off by using the same command (or pressing the backwards P button on the toolbar).

Re: Using Replace to remove line breaks

Posted: Tue Jan 15, 2019 4:16 pm
by esperantisto
You might want to try the Process ends of lines/paragraphs… feature of OOoFBTools.

Re: Using Replace to remove line breaks

Posted: Fri Sep 20, 2019 8:16 am
by Zoe25
The method from RoryOF (Find and Replace) Does work with long documents. (One million words in my books)
SUCCESS! Mostly. Have to add spacing manually in a few hundred areas (Chapters). Better that the >32,000 Line Breaks that were Replaced with one space. (Gives two actual spaces.)
(I tried two spaces in Replace, and it gave 4 spaces. lol)
Yes, the dollar sign (for the backwards P) and one space worked in Find and Replace in under 30 seconds. Regular Expressions checked. :)
Thank you!

Re: Using Replace to remove line breaks

Posted: Fri Sep 20, 2019 8:55 am
by RoryOF
One needs to consider what F&R is doing. I find it is best often to use multiple simple F&R passes, rather than try to do everything in one complex F&R process.