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 PowerShell MVP who has worked in IT for nearly 20 years, and currently serves as a Sr. Database Engineer in Belgium. Always an avid scripter, she attended the Monad session at Microsoft’s Professional Developers Conference in Los Angeles back in 2005 and has worked and played with PowerShell ever since. Chrissy is currently pursuing an MS in Systems Engineering at Regis University and helps maintain RealCajunRecipes.com in her spare time. She holds a number of certifications, including those relating to SQL Server, SuSE Linux, SharePoint and network security. She recently became co-lead of the SQL PASS PowerShell Virtual Chapter. 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 *

*