Join two adjacent strings::delete every second paragraph marker

Hello.
I have a 250-page Writer document with lines of words and numbers. Problem is, they are incorrectly separated by a paragraph mark in the middle. I would like to join them. I have tried regex and fiddling with a macro. Both without expected result. ChatGPT had some suggestions, which didn’t work.

A part of the document is attached, where the first x lines have been joined, and the remaining need to be actioned.

How can this be done without manual intervention?

Thanks for your help.

1400 for help.odt (27.6 KB)

Every second line begins with a tab

If you use the extension Alternative Find & Replace for Writer (AltSearch) then in its dialogue it is just a matter of entering in find field \p\t and in replace field \t then press Replace All

1 Like

@EarnestAl Seems to have a perfectly simply solution.

If this is not adaquate I suggest checking out OooDev’s Python LibreOffice Programming Writer Chapter 9. Text Search and Replace. That also has working examples.

If you need help with OooDev I just ask.

You can also try this macro, tested under Win10 Libre7.5.3.2, I hope it will be functional also under Linux.
It replaces Enter+Tab → Tab, from end position of visible cursor to the end of document. There is only one step in Undo Manager for all replacements (try menu: Edit/Undo).

Sub replaceEnterTab 'replace Enter+Tab only to Tab, from end of visible cursor to the end of document
	on local error goto bug
	dim oDoc as object, oDesc as object, oFound as object, oVCur as object, sEnter$, undoMgr as object, bUndo as boolean
	const sUndo="Replace Enter+Tab"
	oDoc=ThisComponent
	oVCur=oDoc.CurrentController.ViewCursor 'visible cursor
	oVCur.collapseToEnd
	rem detect used Enter according to OS
	select case getGuiType
	case 3 'mac
		sEnter=chr(13)
	 case 4 'linux
		sEnter=chr(10)
	case 1 'win
		sEnter=chr(13) & chr(10)
	case else 'some "ufo", so for example try linux
		sEnter=chr(10)
	end select
	rem searching
	oDesc=oDoc.createSearchDescriptor
	with oDesc
		.SearchRegularExpression=true
		.SearchString="$" 'find Enter
	end with
	oFound=oDoc.findNext(oVCur.End, oDesc) 'find 1st Enter after visible cursor
	do while NOT IsNull(oFound) 'Enter found
		oVCur.goToRange(oFound.Start, false) 'cursor before Enter
		oVCur.goRight(2, true) 'read Enter and next character
		if oVCur.string=sEnter & chr(9) then 'read characters are Enter+Tab
			if bUndo=false then '1st finding, so activate UndoManager
				bUndo=true
				undoMgr=oDoc.UndoManager
				undoMgr.enterUndoContext(sUndo) 'activate UndoManager
				oDoc.lockControllers 'no screen rendering (it is faster)
			end if
			oVCur.String=chr(9) 'replace for Tab
			oVCur.goRight(0, false) 'collapse cursor to the end
		end if
		oFound=oDoc.findNext(oVCur.End, oDesc) 'find next Enter
	loop
	if bUndo then 'there was some finding
		undoMgr.leaveUndoContext(sUndo) 'deactivate UndoManager
		oDoc.unlockControllers 'allow screen rendering
	end if
	exit sub
bug:
	if oDoc.hasControllersLocked then oDoc.unlockControllers
	msgbox("line: " & Erl & chr(13) & Err & ": " & Error, 16, "Bug")
End Sub

:-), AIs must have a lot of examples to build some result, and there is a very few macros on internet how to find Enter+character via LibreBasic macro :-). And for AI’s providers is problematic to say: “I don’t know, too little quantity of input data to build some more-probable-than-shiny-lies result”; or experienced version: “I don’t know, although overly quantity of data and it is just good for nothing anyway.”

1 Like