How to find and replace with libreoffice in terminal?

I want to find and replace variables in template documents. Its a lot of manual work using CTRL + H and replace the variables with Libreoffice Writer GUI. I got a python script to do it but it breaks all the colors and images.

Is it possible to find and replace with some Libreoffice command in terminal that doesn’t break images, added colors etc?

a .odp file is in fact a .zip compressed file

Meaning you can unzip the file and edit content.xml.

Make sure to not change the styles used. E.g. <text:p text:style-name="test"> is a style with the name “test”. If you change it’s name because you try to find all instances of “test” then LO won’t know anymore which styles was applied.

After applying your script you have to create a zip with 0 compression and name it .odt again. E.g. on linux: zip -0 -r ../MyFile_edited.odt ./ (You must be in a directory with only the contents of the original .odt file)

This works fine for me. No styles get broken, no colors removed etc. And if you think of it, it makes sense. If something is broken then it’s only broken because you changed the files source code and contents improperly.


Welcome @libreoffffff !

Perhaps this discussion will lead you to an acceptable solution?

1 Like