How do I find and replace hidden paragraph marks?

Discuss the word processor
Post Reply
iamtherealandy
Posts: 2
Joined: Tue Aug 05, 2008 7:15 pm

How do I find and replace hidden paragraph marks?

Post by iamtherealandy »

Here is my problem:

I have composed my document in Google Docs and now I need to format it in Open Office.

It was my habit to compose in single space but slap an empty line space between paragraphs.

Now I need the document to be evenly double spaced so that there are NO extra spaces between paragraphs.

In MS Word this is done by "finding" two hard paragraph codes in a row and then "replacing" with a single hard paragraph code and a TAB.

That is what I want to do with my Open Office doc. How can I do this?

Thanks so much.

-- Andy
OOo 2.4.X on Ubuntu 8.x
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: How do I find and replace hidden paragraph marks?

Post by acknak »

You can't search across a paragraph boundary in OOo, so your strategy won't work in Writer.

You can search for and remove completely empty paragraphs, like this:

Search for: ^$
Replace with: (empty)
Options/Regular expressions: YES (checked)

If the paragraphs have anything in them, even spaces or tabs, this won't match. In that case, you have to delete them by hand.

Also, you can put text in the "Replace with:" box, but you'll find it next to impossible to put a tab in there.
AOO4/LO5 • Linux • Fedora 23
iamtherealandy
Posts: 2
Joined: Tue Aug 05, 2008 7:15 pm

Re: How do I find and replace hidden paragraph marks?

Post by iamtherealandy »

The document I am working with is hundreds of pages long.

Can you think of any other way to get an evenly formatted double spaced document out of my text without doing it all by hand?
OOo 2.4.X on Ubuntu 8.x
User avatar
foxcole
Volunteer
Posts: 1507
Joined: Mon Oct 08, 2007 1:31 am
Location: Minneapolis, Minnesota

Re: How do I find and replace hidden paragraph marks?

Post by foxcole »

iamtherealandy wrote:The document I am working with is hundreds of pages long.

Can you think of any other way to get an evenly formatted double spaced document out of my text without doing it all by hand?
This is one reason why Google Docs isn't nearly up to snuff yet. It forces you to create spacing between paragraphs by hitting the Enter key. Its style definition should have two kinds of spacing: between lines (which it currently has) and between paragraphs. Unfortunately, it doesn't, and unfortunately, the document wasn't originally written in OOo where you could have made one change to the paragraph style, to change all that spacing. :(

Here is a very good reference on using regular expressions for find and replace:
http://wiki.services.openoffice.org/wik ... _in_Writer
Cheers!
---Fox

OOo 3.2.0 Portable, Windows 7 Home Premium 64-bit
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: How do I find and replace hidden paragraph marks?

Post by acknak »

Can you think of any other way to get an evenly formatted double spaced document out of my text without doing it all by hand?
I can think of lots of ways, but there's no way to guess if they will work with your document or not.

If you can post a couple of pages from your document (your .odt file) as a sample, I expect there's some way to hammer it into shape.
AOO4/LO5 • Linux • Fedora 23
jrkrideau
Volunteer
Posts: 3816
Joined: Sun Dec 30, 2007 10:00 pm
Location: Kingston Ontario Canada

Re: How do I find and replace hidden paragraph marks?

Post by jrkrideau »

iamtherealandy wrote:The document I am working with is hundreds of pages long.

Can you think of any other way to get an evenly formatted double spaced document out of my text without doing it all by hand?
What's wrong with acknak's approach?
LibreOffice 7.3.7. 2; Ubuntu 22.04
User avatar
foxcole
Volunteer
Posts: 1507
Joined: Mon Oct 08, 2007 1:31 am
Location: Minneapolis, Minnesota

Re: How do I find and replace hidden paragraph marks?

Post by foxcole »

iamtherealandy wrote:Can you think of any other way to get an evenly formatted double spaced document out of my text without doing it all by hand?
But acknak isn't suggesting you have to do it all by hand. Use the method he gave for deleting blank paragraphs. The only ones you'd have to remove by hand are the ones where you might have typed a non-printing character such as a space or a tab. If you didn't do that, then the find-and-replace he suggested will take care of all your hundreds of pages.

What might happen then, I'm guessing, is that everything might become single-spaced, no spacing between paragraphs. If that happens, adjust the paragraph style. To do this, click on any paragraph and press F11 to open the Stylist. Right-click on the highlighted paragraph style (probably Default) and choose Modify. Click the Indents and Spacing tab, and adjust the "Above paragraph" and/or "Below paragraph" to set the spacing you want between paragraphs.
Cheers!
---Fox

OOo 3.2.0 Portable, Windows 7 Home Premium 64-bit
Dave
Posts: 1011
Joined: Sun Dec 23, 2007 6:53 pm

Re: How do I find and replace hidden paragraph marks?

Post by Dave »

This worked for me: As acknack suggests do a search and replace with nothing, including regular expressions, but NOT "^$", just "$" [no quotes]. Then double space the entire document. The latter may require first selecting all the text [CTRL-A helps there], then choosing to edit the paragraph from the top formatting menu.

David.
Phil
Volunteer
Posts: 802
Joined: Fri Nov 30, 2007 5:35 pm
Location: Germany

Re: How do I find and replace hidden paragraph marks?

Post by Phil »

Dave wrote:but NOT "^$", just "$"
Why this? Doesn't work with me, at least.

I tested with the following text:

Code: Select all

Test1

Test2

Test3

Test4

Test5

Test6
Using only "$" leads to:

Code: Select all

Test1Test2
Test3
Test4
Test5
Test6
Using "^$" leads to

Code: Select all

Test1
Test2
Test3
Test4
Test5
Test6
acknak wrote:Also, you can put text in the "Replace with:" box, but you'll find it next to impossible to put a tab in there.
Should be working by using "\t", doesn't it?

If I e.g. apply to me last example (single line spacing) above a search for "$" (without "^" this time) and replace by "\t", I get

Code: Select all

Test1	Test2	Test3	Test4	Test5	Test6
(the spaced being tabs).

Regards,
phil
OOo 3.0.1 & DEV-3.1 • WinXP pro 32-bit + SP3 + current patches
Looking for OpenOffice-related information? Try the search engine on OpenOfficeNinja - a great tool!
My favorite extension: Alt. Find & Replace for Writer. All you need and much more...
OOo 2.4.X on Ms Windows XP
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: How do I find and replace hidden paragraph marks?

Post by acknak »

Phil wrote:
Dave wrote:but NOT "^$", just "$"
Why this? Doesn't work with me, at least.

I tested with the following text:
...
acknak wrote:Also, you can put text in the "Replace with:" box, but you'll find it next to impossible to put a tab in there.
Should be working by using "\t", doesn't it?

If I e.g. apply to me last example ...
Just my holey memory on both counts--thanks for testing and setting it straight.

I can't keep all of OOo's idiosyncrasies straight; usually I just fool around with it until it works ;-)

Dave's suggestion of using a plain '$' works for me, too. I'm not sure what's happened in your example.

I thought a plain '$' matched any paragraph boundary, so '^$' was needed to match empty paragraphs. It seems that '$' only matches empty paragraphs.
AOO4/LO5 • Linux • Fedora 23
Phil
Volunteer
Posts: 802
Joined: Fri Nov 30, 2007 5:35 pm
Location: Germany

Re: How do I find and replace hidden paragraph marks?

Post by Phil »

acknak wrote:I can't keep all of OOo's idiosyncrasies straight; usually I just fool around with it until it works ;-)
I fully agree it's really weird sometimes! :)
acknak wrote:Dave's suggestion of using a plain '$' works for me, too. I'm not sure what's happened in your example.
My fault: Tested this on an old 2.3.1 install, which obviously contained a bug. Just tested again on 2.4.1 and 3.0 Beta 2, and the results for using both "$" and "^$" is now identical (and the correct result you would expect according to my 3rd code box above).
acknak wrote:I thought a plain '$' matched any paragraph boundary, so '^$' was needed to match empty paragraphs. It seems that '$' only matches empty paragraphs.
I got quite puzzled as well!
So I tested again. Used screenshots this time to see special characters.

Here's the test case:
Original.png
Original.png (3.56 KiB) Viewed 12112 times
Doing a replace of "$" by the character "#" leads to:
Replace1.png
Replace1.png (2.48 KiB) Viewed 12113 times
Doing a replace of "^$" by the character "#" leads to:
Replace2.png
Replace2.png (3.38 KiB) Viewed 12114 times
To sum it up, "^$" applies to really empty paragraphs only (excluding spaces and tabs), whereas "$" seems to apply to paragraphs that do not contain text, but may contain spaces and tabs. The latter might indeed be helpful in the context of formatting documents.

Regards,
phil
OOo 3.0.1 & DEV-3.1 • WinXP pro 32-bit + SP3 + current patches
Looking for OpenOffice-related information? Try the search engine on OpenOfficeNinja - a great tool!
My favorite extension: Alt. Find & Replace for Writer. All you need and much more...
OOo 2.4.X on Ms Windows XP
Phil
Volunteer
Posts: 802
Joined: Fri Nov 30, 2007 5:35 pm
Location: Germany

Re: How do I find and replace hidden paragraph marks?

Post by Phil »

(not more than 3 attachments allowed per post, therefore I continue in a new one)

Note that it also works for multiple consecutive paragraphs if replacing by an empty string instead of "#". So replacing "$" by nothing leads to:
Replace3.png
Replace3.png (1.64 KiB) Viewed 12143 times
OOo 3.0.1 & DEV-3.1 • WinXP pro 32-bit + SP3 + current patches
Looking for OpenOffice-related information? Try the search engine on OpenOfficeNinja - a great tool!
My favorite extension: Alt. Find & Replace for Writer. All you need and much more...
OOo 2.4.X on Ms Windows XP
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: How do I find and replace hidden paragraph marks?

Post by acknak »

Interesting--thanks, Phil. Nice work!

I wonder if any of this is helpful, or if the poster is long gone?

Oh well, the info is here if anyone else comes looking for it.
AOO4/LO5 • Linux • Fedora 23
Phil
Volunteer
Posts: 802
Joined: Fri Nov 30, 2007 5:35 pm
Location: Germany

Re: How do I find and replace hidden paragraph marks?

Post by Phil »

You're welcome! 8-)
acknak wrote:I wonder if any of this is helpful, or if the poster is long gone?
Yes, that's a good question. :mrgreen:

Anyway, I came across that thing some time ago, as I had to reformat some text file, but didn't analyze in detail at that time.
So it was a good opportunity to catch up on that.
And as you say: it can serve as a reference for future questions.
OOo 3.0.1 & DEV-3.1 • WinXP pro 32-bit + SP3 + current patches
Looking for OpenOffice-related information? Try the search engine on OpenOfficeNinja - a great tool!
My favorite extension: Alt. Find & Replace for Writer. All you need and much more...
OOo 2.4.X on Ms Windows XP
User avatar
Portree
Posts: 1
Joined: Wed Aug 13, 2008 5:33 pm
Location: Somewhere, wishing I was somewhere else.

Re: How do I find and replace hidden paragraph marks?

Post by Portree »

Okay, that is great info. Maybe you might be able to help me out with a similar issue.

I have a listing that has a lot of lines where the beginning and end of the line are the same but the content in between differs. I would like to delete all of them in one sweep. How do you use find and replace to get rid of a line when it is not blank? For example:
snapshot1.png
snapshot1.png (7.56 KiB) Viewed 12052 times
If I do a find and replace using "a.*e$" as the search string and leave the 'Replace with' blank (with regular exp. checked) I get:
snapshot2.png
snapshot2.png (6.92 KiB) Viewed 12054 times
This left a blank line when I had hoped that it would take out the line entirely like "^$" does for blank lines.
I did try "^a.*e$" as well and got the same result.

Any thoughts? I would really appreciate it.
Thanks.
OOo 2.4.X on openSuse 11 + Windows XP (in VBox)
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: How do I find and replace hidden paragraph marks?

Post by acknak »

How do you use find and replace to get rid of a line when it is not blank?
That is not possible with OOo Writer, out of the box.

You must either use the extension mentioned previously, or use several steps. E.g., use your example to first make the lines empty, then perform a second pass to remove the empty lines.
AOO4/LO5 • Linux • Fedora 23
Spinner
Posts: 1
Joined: Mon Oct 06, 2008 8:58 am

Re: How do I find and replace hidden paragraph marks?

Post by Spinner »

I know it's been over a month since this thread was active, but just incase anyone stumbles over this page at a future date, the best solution to the originally posted query is as follows:

In 'More Options', check 'Regular Expressions'
Search for: "^( *\t*)*$" [no quotes] (NOTE that the first character in the parenthesis is a space, followed by *\t*)
Replace with: <blank> [leave empty]
This will delete any whitespace lines, leaving you with purely text and carriage return lines.

The multiple carriage return lines can then be stripped out as previously stated with:
Search for: "^$" [no quotes]
Replace with: <blank> [leave empty]

[=== EXAMPLE ===]
So working on test input:

Code: Select all

Line 1

Line 2
<sp><sp><sp>
Line 3
Line 4
<tab><tab><tab>
Line 5

<tab><tab><sp><sp><sp><tab><tab>
Line 6
<sp><sp><sp><tab><tab><tab>
Line 7
<tab><tab><sp><sp><sp>
Line 8

<sp><sp><sp>legit spaces<sp><sp><sp>
<tab><tab>legit tabs
<tab><tab><sp><sp><sp>legit tabs and spaces<sp><sp><tab>
Line 9
After running the search and replace on "^( *\t*)*$" you will get:

Code: Select all

Line 1

Line 2

Line 3
Line 4

Line 5


Line 6

Line 7

Line 8

<sp><sp><sp>legit spaces<sp><sp><sp>
<tab><tab>legit tabs
<tab><tab><sp><sp><sp>legit tabs and spaces<sp><sp><tab>
Line 9
Then you can run the search and replace on "^$" to give you:

Code: Select all

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
<sp><sp><sp>legit spaces<sp><sp><sp>
<tab><tab>legit tabs
<tab><tab><sp><sp><sp>legit tabs and spaces<sp><sp><tab>
Line 9
I'm sure there's a way to do it all in one go with regular expressions, but my first guess of regexp which was "^[ \t]*$" didn't seem to work, but a 2 step approach doesn't take that much longer and does just the same thing.

Hopefully this info will come in handy for someone at some stage in the future.
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: How do I find and replace hidden paragraph marks?

Post by acknak »

Good explanation--thanks for the follow-up!
I'm sure there's a way to do it all in one go with regular expressions...
Nope. Two steps, as you showed, is the best you can do without a macro or extension.
AOO4/LO5 • Linux • Fedora 23
daviddrescher1
Posts: 1
Joined: Mon Jan 12, 2009 5:10 pm

Re: How do I find and replace hidden paragraph marks?

Post by daviddrescher1 »

Thank you. The solution works beautifully :D
OOo 3.0.X on MS Windows Vista
Post Reply