How to Split Text (TXT) Files by Line in Power Automate
Text files like system/application logs, CSV data, configuration files, and even day-to-day notes can all be divided into independent lines for more efficient processing.
Processing text (txt) files in Power Automate
Assuming we aren’t interested in writing a bunch of new code, Power Automate is a great place to handle a mundane file processing task like this. Using the Cloudmersive Document Conversion connector, we can easily divide any text file into a series of separate lines and process those lines however we see fit downstream in our flow.
We’ll walk through a brief example of this now. We’ll split the below notepad document (containing Lorem Ipsum text) into series of separate lines, and we’ll see how that shows up in our Power Automate flow later on.
Set up an Instant cloud flow
We’ll use an instant cloud flow in this context so we can select an individual file (like the above) from our system.
Retrieve a text file using a Get file cotent action
First things first, we’ll use a Get file content action to retrieve our text file from our system.
Search for the Cloudmersive Document Conversion connector
Next, we’ll add a new action and search for Cloudmersive connectors. We’ll find several Cloudmersive connector options available; we’re looking for the Document Conversion connector with the green logo.
We’ll click “See more” to view the actions list, and from there, we’ll search for the action we need. It’s called Split a single Text file (txt) into lines.
Create and authorize a Cloudmersive API connection
After we select this action, it’s time to configure our Cloudmersive connection. We can authorize our connection with a free API key (the same API key I’m using in this walkthrough) by creating a free account on the Cloudmersive website. With a free API key, we can use any Cloudmersive connector, and we get up to 800 API calls/month with no commitments.
Configure the “Split a single Text file into lines” request
Configuring our request is simple — we’ll pass our text file content to the Input file parameter, and we’ll then create a random name in the (file name) parameter.
Reviewing dynamic content from the split operation
Now we’ll add & open up a random action (in my case, a Condition) so we can view dynamic content produced from this action.
As we can see in the above screenshot, the Split a Text file into lines action returns the line count, line contents, and line numbers, to our flow as individual dynamic content items. We can use all of these information arrays downstream in our flow when we process or store text content.
Conclusion
In this flow, we learned how to find and configure a Cloudmersive Document Conversion connector action in Power Automate that splits text files into a series of separate lines with additional information.
We can use this flow to assist in processing all kinds of important text-based documents, such as those mentioned earlier (system logs, CSV files, etc.)