Search and Replace Text string | Community
Skip to main content
Level 3
April 7, 2023
Solved

Search and Replace Text string

  • April 7, 2023
  • 3 replies
  • 3842 views

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.. 

 

Best answer by DPrakashRaj

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 

3 replies

Level 2
April 7, 2023

Hi, 

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

BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
April 8, 2023

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. 

DPrakashRaj
Community Advisor
DPrakashRajCommunity AdvisorAccepted solution
Community Advisor
April 8, 2023

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 

Level 2
November 24, 2023

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?

DPrakashRaj
Community Advisor
Community Advisor
November 24, 2023

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)