How to globally search and modify content
On this page
Description
Often the need arises to find pages that have certain content and modify it slightly. If the number of pages is larger, making manual modifications can be painful and error prone. Automation can help, but you have to make sure that you are modifying exactly what you want and not something unintentional. See also this user question for a discussion on this topic.
Updating storage format
Always be careful updating storage format data and make sure you test before doing mass updates.
Go to How to Find Confluence Pages and Then Do Something for techniques for finding content.
Links
- How to Find Confluence Pages and Then Do Something
- How to Use SQL to Find Pages
- How to make global changes to comments
- Advanced Searching With CQL
Example 1: Changing a url
Changing a link. For instance: http://myjira.com to http://mynewjira.com.
Steps
Setup an example page
--action storePage --space xxx --title test --parent @home --content "aaa http://myjira.com bbb"
Construct a modifyPage action for a single page using a simple text replace. Since : (colon) is in the text and is the default key:value separator for CLI, use # instead using the special parameter (spaces are significant!)
--action modifyPage --space xxx --title at --findReplace "http://myjira.com#http://mynewjira.com" --special " #"
Run against all pages with the link (using unix style escaping - see Tips). Run against your test space first before using @all.
--action runFromContentList --cql "type=page" --common "--action modifyPage --id @pageId@ --findReplace \"http://myjira.com#http://mynewjira.com\" --special \" #\" "
Results
Run: --action modifyPage --id 112197680 --findReplace "http://myjira.com#http://mynewjira.com" --special " #" Page modified: 'at' in space: xxx. Page has id: 112197680 ...
Example 2: Renaming a macro
There are a few cases why you may need to rename a macro:
- A user macro may need a better name or may conflict with macro from a new plugin
- A macro may no longer be valid because you have discontinued a plugin or