[Solved] Find and replace space and paragraph characters

Discuss the word processor

[Solved] Find and replace space and paragraph characters

Postby HaRo » Tue May 21, 2019 7:44 am

I lost my MS Office in disk mishap. I'm trying OO. A problem. I frequently collect a block of words separated by 4 or 5 spaces.

1. Using MS Word, I find double space (put cursor into find box and press space bar twice) and replace with single space (put cursor into replace box and press space bar once.) Replace all. Repeat till words are only separated by a single space.
2. Then I convert to a list. Find space (put cursor into find box and press space bar once) and replace with paragraph (put cursor into replace box and type ^p).
3. Then sort into alphabetical order.
4. Change list to block. Find paragraph mark (put cursor into find box and type ^p) and replace with five spaces (put cursor into replace box and press space bar five times.)

How do I do the equivalent thing with OO? I can do the sorting, but not the rest of it.
Last edited by Hagar Delest on Sun May 26, 2019 12:47 pm, edited 1 time in total.
Reason: tagged solved
Open Office 4.1.6 on Windows 7
HaRo
 
Posts: 5
Joined: Tue May 21, 2019 6:30 am

Re: find and replace space and paragraph characters

Postby RoryOF » Tue May 21, 2019 9:12 am

Your step 1 is OK
Step 2, Find a space, Replace \n and ensure "More options" is set to "Regular Expressions"
Step 3 should be OK
Step 4, Find $, Replace a space, "More options" set to "Regular Expressions"

Above sequences just now tested and working correctly.
Apache OpenOffice 4.1.6 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29294
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find and replace space and paragraph characters

Postby HaRo » Wed May 22, 2019 8:22 am

Thanks, but step 1 didn't work. I set up a block of words with varying numbers of spaces between them. Put five spaces into find box, one into replace box. It replaced all the fives with one. Then I put two into Find box, left one in replace box. Got "search key not found", even though there were plenty of places with multiple spaces. Tried with four spaces (since there were some words separated only by four spaces) and the same thing happened.
Open Office 4.1.6 on Windows 7
HaRo
 
Posts: 5
Joined: Tue May 21, 2019 6:30 am

Re: Find and replace space and paragraph characters

Postby RoryOF » Wed May 22, 2019 9:12 am

If I am faced with multiple spaces I normally Find two spaces, replace with one space (no need for Regular experessions option in this case) and run that search repeatedly until "not found". Try again with "Regular Expressions" not checked

I am not driving your computer: as I wrote, my sequence had been tested with the Find and Replace specifiers I noted.

 Edit: If you are pasting from Internet sources, it is possible (indeed, likely) that what you are seeing as spaces (ASCII character 020H) are "non breaking spaces" (ASCII character 0A0H). Find and Replace does not treat these as equivalent. To disclose them, turn on /View /non printing characters; such non breaking spaces will show as shaded spaces. If so, select one of these, Copy it, then Paste into Find box. Replace with space, press Replace all button. Now Find should continue to find and replace ordinary spaces when you instruct it to do so, 
Apache OpenOffice 4.1.6 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29294
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find and replace space and paragraph characters

Postby Lupp » Wed May 22, 2019 1:25 pm

There are many ways to fine-tune RegEx for such tasks. RegEx are much more powerful than the means MS Word offers (afaik).
Code: Select all   Expand viewCollapse view
\s
e.g. will accept any kind of whitespace, including tab marks and hard line breaks. Consciously used together with with a quantifier like
Code: Select all   Expand viewCollapse view
{2,}
with an ordinary space in "Replace with", and with the option "Current selection only" it may help in the present case.
See the attached example. It also contains a bit of additional information.

===Editing; for completeness only===
Paragraph breaks are not accepted by any RegEx in OpenOffice F&R 'Search for' except:
-1- denoted by the special character "$" as a special kind of "zero-length lookahead assertion".
-2- by "$" again like actual characters if a sequence of empty paragraphs shall be addressed.
The whitespace characters accepted by "\s" do not include paragraph breaks.
Attachments
aoo98107FandR_spaces_1.odt
(35.44 KiB) Downloaded 11 times
Last edited by Lupp on Wed May 22, 2019 2:41 pm, edited 3 times in total.
On Windows 10: LibreOffice 6.2 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 2523
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Find and replace space and paragraph characters

Postby RoryOF » Wed May 22, 2019 2:07 pm

I usually use multiple simple F&R operations, Lupp. Note that your formula, given in the body of your reply, can affect some page style changes, so caution is suggested.

 Edit: I used a copy of an existing document (A5 pages) inserted into a blank Writer document, and failed to notice that the Default style of the blank document was retained (A4 page) rather thsn the Default style (A5 page) used in the inserted document. 
Apache OpenOffice 4.1.6 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29294
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find and replace space and paragraph characters

Postby erbsenzahl » Wed May 22, 2019 4:03 pm

@HaRo:
Your Swiss knife could be the AltSearch.oxt extension.

When downloaded install it via Tools menu > Extension Manager and start OpenOffice anew.

To replace spaces into paragraphs and return use for paragraph only \p. That's all. As simple as in Word.
OpenOffice 3.4.1 and 4.1.6 on LinuxMint 19-64 Mate, rarely W7-64 pro and W10-64 pro; LibreOffice current versions
(author is no native speaker)
erbsenzahl
Volunteer
 
Posts: 139
Joined: Tue Apr 18, 2017 8:23 am
Location: Germany

Re: Find and replace space and paragraph characters

Postby RoryOF » Wed May 22, 2019 4:37 pm

A possible problem users may find with AltSearch is that compared with OO's F&R it takes a long time in any document of size (hundreds of pages).
Apache OpenOffice 4.1.6 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29294
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Find and replace space and paragraph characters

Postby HaRo » Thu May 23, 2019 5:07 am

Thanks, erbsenzahl. I'll give it a try.
Open Office 4.1.6 on Windows 7
HaRo
 
Posts: 5
Joined: Tue May 21, 2019 6:30 am

Re: Find and replace space and paragraph characters

Postby HaRo » Thu May 23, 2019 6:07 am

Nope. The first part works fine, both for English and Chinese. I set up a block of words with varying spaces between them, use space bar to put double spaces in find, single in replace, and replace all. Repeat until there is only a single space between them.
But when I put space in find, and \p into replace, it refuses to do anything. I've tried it with end-of-word, any-space, and non-breaking-space from the list. It won't find them, won't replace them.
Open Office 4.1.6 on Windows 7
HaRo
 
Posts: 5
Joined: Tue May 21, 2019 6:30 am

Re: Find and replace space and paragraph characters

Postby RusselB » Thu May 23, 2019 6:47 am

The following was done using the default OpenOffice Find & Replace dialog in Writer.
This has been briefly tested.
In the Find & Replace dialog put \s+ in the Find section and \n in the Replace section.
Select More Options and ensure the Regular expressions is checked.
My test shows that this finds multiple occurrences of the space character and then replaces them with a single paragraph character.
OpenOffice 4.1.6 and LibreOffice 6.0.6.2 on Windows 7 Pro & Ultimate
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
User avatar
RusselB
Moderator
 
Posts: 5300
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: Find and replace space and paragraph characters

Postby HaRo » Thu May 23, 2019 7:16 am

By George, you've got it!

Thanks, RusselB.

On my quick tests, that will do what I want both for English and Chinese!

I can replace multiple places with a single para mark, sort (OO doesn't automatically recognise Chinese, but gives more sorting options for Chinese than MSWord) and the replace the para marks with multiple spaces.

I'll come back and moan some more if I have problems with it, but right now it looks fine.
Open Office 4.1.6 on Windows 7
HaRo
 
Posts: 5
Joined: Tue May 21, 2019 6:30 am

Re: Find and replace space and paragraph characters

Postby RoryOF » Thu May 23, 2019 8:36 am

HaRo wrote:Nope. The first part works fine, both for English and Chinese. I set up a block of words with varying spaces between them, use space bar to put double spaces in find, single in replace, and replace all. Repeat until there is only a single space between them.
But when I put space in find, and \p into replace, it refuses to do anything. I've tried it with end-of-word, any-space, and non-breaking-space from the list. It won't find them, won't replace them.


When using the \n in either Find or Replace one must use More Options: Regular expressions.
Apache OpenOffice 4.1.6 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29294
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland


Return to Writer

Who is online

Users browsing this forum: No registered users and 15 guests