Get-Content and show control characters such as `r – visualize control characters in strings

Question:

What flag can we pass to Get-Content to display control characters such as \r\n or \n?

What I am trying to do, is to determine whether the line endings of a file are in the Unix or Dos style. I have tried simply running Get-Content, which doesn’t show any line ending. I have also tried using Vim with set list, which just shows the $ no matter what the line ending is.

I would like to do this with PowerShell, because that would be mighty useful.

Answer:

One way is to use Get-Content’s -Encoding parameter e.g.:


If you have the PowerShell Community Extensions, you can use the Format-Hex command:

If you really want to see “\r\n” in the output than do what BaconBits suggests but you have to use the -Raw parameter e.g.:

Outputs:

Source:

Get-Content and show control characters such as `r – visualize control characters in strings by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply