Libreoffice Writer replace word AND paragraph break

Questions about applications and software
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
begtognen
Level 3
Level 3
Posts: 100
Joined: Mon Aug 29, 2016 4:33 am

Libreoffice Writer replace word AND paragraph break

Post by begtognen »

Libreoffice Writer: 7.3.7.2

I'd like to do a search and replace on a document and replace a word AND a paragraph break with a space.

Here's why: I have a handwriting to text tablet. When I start a new page on the tablet, the text converter inserts a paragraph break, so any paragraphs that stretch across two pages have an unwanted paragraph break in the middle. (This isn't possible to change.)

I can easily put in a marker word, like "xjxj", at the bottom of a page before when the paragraph continues on the next page.

SAMPLE:
When it's converted and put into Libreoffice Writer it looks like xjxj
and then the rest of the sentence.

I'd like to be able to replace xjxj AND the paragraph break with a space.

Using Regular Expression in search and replace I've tried these in the search box, which don't work:

xjxj$
xjxj $
\xjxj$
\xjxj $

This does work:

$

But of course is useless because there's no marker word.

Is this something that's possible in Libreoffice Writer?

Thanks so much for your help.
Last edited by LockBot on Sat Sep 23, 2023 10:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
mikeflan
Level 17
Level 17
Posts: 7136
Joined: Sun Apr 26, 2020 9:28 am
Location: Houston, TX

Re: Libreoffice Writer replace word AND paragraph break

Post by mikeflan »

What happens when you turn off the regex and just replace xjxj with a space?
Is that exactly what you want?

In LO Writer "$" is a Paragraph Break if you have regex checked.
Oddly enough, if you replace Paragraph Breaks with anything, Ctrl-Z will not undo it :?
Wakatakakage
Level 3
Level 3
Posts: 154
Joined: Wed Apr 21, 2021 10:34 pm

Re: Libreoffice Writer replace word AND paragraph break

Post by Wakatakakage »

I'm no expert, but it looks like it may be challenging, but not impossible. The OpenOffice wiki has a nice description of this specific situation. I believe that all of the details apply equally to LibreOffice. It appears to be a limitation of LibreOffice's regular expression engine.

The OpenOffice wiki describes a multi-step workaround, involving replacing all paragraph marks with a distinct, unique character string, manipulating those with a search & replace, and then restoring the paragraph marks.

Another possible solution is the Alternative find & replace for Writer (AltSearch) extension. I saw a few references to this extension being able to do what you ask. But I have not tried it myself, and the most recent version was released in 2017.

Does your tablet produce LibreOffice format files specifically? If they are just plain text files, I found a sed command that can do as you wish. Although even that was a great deal more complicated than I would have thought.

Code: Select all

sed ':a;N;$!ba;s/xjxj\n/ /g' input.txt >output.txt
See this Stack Overflow question for an explanation of the syntax.
begtognen
Level 3
Level 3
Posts: 100
Joined: Mon Aug 29, 2016 4:33 am

Re: Libreoffice Writer replace word AND paragraph break

Post by begtognen »

Wakatakakage - Thanks so much, this was so helpful. It never occurred to me to replace the paragraph break in a program that I KNOW does it just fine, and as the output is simple text I was able to do just that using Scite. Worked like a charm. I appreciate your time.
Wakatakakage
Level 3
Level 3
Posts: 154
Joined: Wed Apr 21, 2021 10:34 pm

Re: Libreoffice Writer replace word AND paragraph break

Post by Wakatakakage »

I'm glad that you were able to find a solution.
Locked

Return to “Software & Applications”