How to Detect the Line Endings of a Text File in Power Automate

Cloudmersive
4 min readNov 22, 2024

--

Different systems use different line endings in text files (.txt) to indicate where one line ends and the next begins. It’s critical that we understand which line endings a text file is using before we attempt to save that file on any OS (or send that text content to any API).

If we’re processing text files through Power Automate, we can determine the line endings in a text file using the Cloudmersive File Processing connector. We’ll get a straightforward response object indicating the Primary Newline Type (e.g., Windows, Unix, etc.), the Primary Newline Terminator (e.g., \r\n for Windows), and the Input Length of the text string (the exact number of characters present).

In this article, we’ll set up a quick test case for this connector action using an instant cloud flow.

We’ll start by using a Get file content action to grab an example text file from our system. If we don’t have a test file on hand, we can easily create one by opening our system’s default text editor (e.g., Notepad for Windows), entering some content into our text editor, and saving the file with a .txt extension.

Next, we’ll add a new action and type “Cloudmersive” into the connector search bar.

We’ll locate the Cloudmersive File Processing connector by scrolling down the resulting connector list.

We’ll click “See more” to view the full actions list, and from there, we’ll CTRL+F search for an action titled Detect line endings of a text file.

Upon selecting this action, we’ll be prompted to create our Cloudmersive File Processing connection and authorize that connection with a Cloudmersive API key. We can get a free API key by visiting the Cloudmersive website and creating a free account (this allows a limit of 800 API calls per month with zero additional commitments).

After we’ve created our connection, we’ll enter our text file dynamic content in the initial Input File parameter, and we’ll then enter a file name in the second parameter. We don’t need to use our file’s real name for this action to work correctly; we’re just labeling our content when it’s passed to the endpoint.

We’re now ready to identify the line endings of our example text file.

In my example flow, I’m imagining that I only want text files with the Primary Newline Type value “Windows” to move forward towards any subsequent file processing actions, so I’m adding a condition that filters body/PrimaryNewlineType for the string “Windows”.

When we’re ready, we’ll save and test our flow and review the outputs.

In my condition, we’ll notice the expressionResult is “true”, meaning the body/PrimaryNewlineType value indeed contained “Windows”.

By opening our Detect line endings action, we’ll be able to review the full response object.

I’m working in a Windows environment, and my action correctly identified the Carriage Return and Line Feed Primary Newline Terminators as Windows-based.

Unix, Linux, and MacOS would return “\n” (Line Feed) instead.

Now we can make intelligent decisions in our flows based on the formatting of text files.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet