Removing ^M Characters from Files in ESXi

As part of a build process for an ESXi server – on of the stages are to upload a valid SSL certificate to the ESXi server.
When copying the certificate over to the host with pcsp for some reason they file is always malformed when going over. If you do a cat rui.crt you will see no issue, but if you do a vi rui.crt then you will see that each and every line has a ^M at the end of it – this is because the file is a dos format file.

dos format

I finally found a to remove them – and it was not easy to find.
Both tr and dos2unix are not available on ESXi

sed 's/'"$(printf '\\015')"'$//  
s/'"$(printf '\\032')"'$//' rui.crt > rui.new

That produces a clean file.

unix format

Phew – now I can rest easy…

Update:
Thanks to the comment received from JR below it is even easier

sed 's/.$//' < rui.crt > rui.new