One of my colleagues asked me to assist with replacing text in a text file stored in a SharePoint document library, so that he can send an email with the updated document file to the client.
We can achieve this by using the replace() function in Power Automate.
In this tutorial, I will explain how you can replace text in a file present in a SharePoint document library using Power Automate.
Check how you can do!
Replace Text in SharePoint File by Power Automate
Let’s consider that I have a SharePoint document library that consists of various file types, such as .docx, .txt, .ppt, and .xlsx.
You can see the SharePoint library in the image below: Invoice Documents

Here, my requirement is to replace the string present in the text file with another text.
Suppose the text file consists of Customer Invoice Details, where I wanted to replace ‘Invoice Number’ with ‘Invoice ID’.

To achieve this, I will create a manual trigger flow in Power Automate that a button click can trigger.
To achieve this, follow the steps mentioned below:
- On Power Automate, create an ‘Instant cloud flow’. If you’re not familiar with creating one, check out Instant Cloud Flow in Power Automate.
- Next, add ‘Get file content‘ to retrieve the content from the text file. Provide the below-mentioned parameters.
- Site Address: Provide the SharePoint site address.
- File Identifier: Select the file from the open folder icon.

- Then, take a ‘Compose‘ action to provide the replace expression that replaces the text from the file.
- Inputs: Enter the expression below.
replace(outputs('Get_file_content')?['body'],'Invoice Number','Invoice ID')From the expression, to get the body of a file from the outputs of Get file content, you need to use the [‘body‘] in the expression.

- To view the output, I will send an email with the replaced text file. So, I will add ‘Send an email(V2 )‘ action: set To, Subject, and Body parameters.
- Attachments: Click on the switch details to input the array icon. Paste the below code.
[
{
"Name": "Customer Invoice Details.txt",
"ContentBytes": @{outputs('Compose_-_Replace_Text')}
}
]Replace the Outputs of compose with your compose outputs in the above expression.

- The flow is ready now. Save the flow to the canvas. Then, test it by manually clicking the Runflow button.
- When the flow executes successfully, an email will be sent with a text file attachment, where you can see that the text “[Invoice Number]” has been replaced with another text string, “[Invoice ID]”.
Outputs: Reference the image below.


This is how you can replace a text in a text file using the replace() function in Power Automate.
Hope you found this article informative. Do mention your suggestions on this tutorial in the comments section.
You can check out other Power Automate Tutorials:
- Replace String in JSON using Power Automate
- Replace Value in an Array in Power Automate
- Replace Apostrophe in String in Power Automate
- Replace Special Characters in a String using Power Automate

After working for more than 18 years in Microsoft technologies like SharePoint, Microsoft 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (12 times). I have also worked in companies like HP, TCS, KPIT, etc.