Skip to main content
Level 3
Apr 7, 2023 6:07 PM UTC
Solved

Search and Replace Text string

Hi All, 

We need to replace a specific text string, such as "Hello World," with "Greetings, Earthlings!" on approximately 2000 pages, text string is part of content fragment, What would be the best approach to accomplish this in AEM?

 

TIA.. 

 

DPrakashRaj
DPrakashRajAccepted solution
Community Advisor
Apr 8, 2023 2:57 AM UTC

There are various ways to accomplish this. You can write a server or script to do this. You can also use groovy script as well as sling pipes. All the above will help you in automation 

10 replies

Level 2
Apr 7, 2023 9:04 PM UTC

Hi, 

Kindly refer to find and replace here . Also, check out this tool.

Translate
BrianKasingli
Adobe Champion and Community Advisor
Adobe Champion and Community Advisor
Apr 8, 2023 1:02 AM UTC

I suggest you write a custom servlet to find all content fragments under a specific path where it will find all instances of Hello World, replaces the word with Greetings, Earthlings!, and then it republishes all content fragments if they are already replicated; If content fragments are not yet activated, do nothing. Your servlet should also have a "mode=dry run" mode where it will just return you a list of all affected content fragments before the actually replace. 

Translate
DPrakashRaj
Community Advisor
DPrakashRajCommunity AdvisorAccepted solution
Community Advisor
Apr 8, 2023 2:57 AM UTC

There are various ways to accomplish this. You can write a server or script to do this. You can also use groovy script as well as sling pipes. All the above will help you in automation 

Translate
Level 2
Nov 24, 2023 4:55 PM UTC

Is this not inefficient and a bit dangerous having everyone write a script / servlet that wants what is basic functionality?

 

I'd like to have search and replace across my library of content fragments but to write it myself seems a bit poor?

Translate
DPrakashRaj
Community Advisor
Community Advisor
Nov 24, 2023 5:25 PM UTC

Aem doesn’t provide you any ootb functionality that provides search and replace for the content. Atleast I am not aware of this. If you don’t want to write any type of automation then you can go with something called school way of creating a package of your content fragment and do a search and replace in the package directory after extraction using some ID and then making the package again and deploying it on aem. That’s the non-technical way I can think of without writing any automation (script/servlet)

Translate