Quick tip: Fix those line endings

In dealing with data transferred between different operating systems, we often come across the irritating phenomenon of, what might appear as, a file without any spaces in them. This is of course because of different end of line (EOL) characters, and I’m going to show you a quick and easy way of using PowerShell to “fix” these for Windows.

This is a nice example of PowerShell being nice, and doing stuff for us. For instance, when you use Get-Content to read the contents of a text file, even though it’s using NIX-style line endings, PowerShell will automatically detect this and replace it with the appropriate line endings for Windows. This means that we can use the following one-liner to quickly fix a file with foreign EOL:

Get-Content -Path $pathToInputFile | Out-File -FilePath $pathToOutputFile

This will automatically replace the line endings with the proper Windows EOL (CR+LF).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s