Use regex to remove Include macro from space(s) using Confluence CLI
Overview
This article describes the steps involved in removing a macro from one or more spaces through regex patterns using the Confluence Command Line Interface (CLI).
Step-by-step guide
You can remove a macro by using the runFromPageList and modifyPage actions. You can choose between the two actions based on your needs.Â
- The runFromPageList action allows you to search for the page as per the specified criteria.
The modifyPage action allows you to modify the storage format of the page and remove the Include macro from all the pages in a space.
- Ensure that you update the confluence.sh/confluence.bat file with the server, user, and password details.Â
To remove an Include Macro from all the pages in a space, execute the following CLI command:Â
--action runFromPageList --space "TEST" --common "--action modifyPage --space "TSETSPACE" --id @pageId@ --special \" # \" --findReplaceRegex \"<ac:structured-macro ac:name=\"include\" (?s).*</ac:structured-macro># \""
Replace the space name with the intended name of the space in the above syntax.
To remove a Macro from all the pages on a Confluence site, execute the following CLI command:
--action runFromPageList --space "@ALL" --common "--action modifyPage --space "@ALL" --id @pageId@ --special \" # \" --findReplaceRegex \"<ac:structured-macro ac:name=\"include\" (?s).*</ac:structured-macro># \""
If you want to remove other macros from the page(s), you need to specify a different regex pattern. Please refer to How to use regular expression for further details.
- We highly recommend that you test the actions on a test instance before executing it in the production environment.Â
- As a precautionary measure, take a back up of the instance before executing the command.