VI: Automatically Set vi To Support Windows-Compatible Carriage Returns

Earlier today, I pasted some code into a Linux-based vi via putty/ssh, saved it, zipped it, and downloaded it to a Windows machine. The result was pooh; the code ran but was garbled in notepad. I wondered if I could somehow run a command in Linux to clean/convert all the carriage returns. One of my friends at Microsoft, Lee, suggested unix2dos (and its nemesis dos2unix).. just what I was looking for! However, if I didn’t want to run unix2dos each time I saved the file, I could set vi’s file format to dos at startup by adding the following alias to my .bashrc file

alias vi=’vi -c "set ff=dos"’

Not such a great idea for unix-centric folk but a great thing for me :) As for a Windows equivalent of unix2dos… Lee, a developer on the Powershell team, just told me that you can run the following in Powershell to accomplish the conversion: Get-Content unixfile.txt | Set-Content dosfile.txt. I really need to get around to scripting in Powershell; it will no doubt save me a ton of time in the long-run. Until then, though, I’ll continue to cater to old school VBScript-loving Windows Admins.

Chrissy is a Cloud and Datacenter Management & Data Platform MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, and holds a number of certifications, including those relating to SQL Server, Linux, SharePoint and network security. You can follow her on Twitter at @cl.

Posted in Linux
3 comments on “VI: Automatically Set vi To Support Windows-Compatible Carriage Returns
  1. Jeffrey Snover says:

    > I really need to get around to scripting in Powershell; it will no doubt save me a ton of time in the long-run. Until then, though, I’ll continue to cater to old school VBScript-loving Windows Admins.

    Red pill vs Blue pill. Take the leap.

    Jeffrey Snover [MSFT]
    Windows PowerShell/MMC Architect
    Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
    Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

  2. jlg says:

    unix2dos in powershell: excellent.

Leave a Reply

Your email address will not be published. Required fields are marked *

*