As system administrators, we often have to login to servers and modify files – whether they’re configuration files or php scripts. Occasionally these are files which may have previously been edited and uploaded by somebody using Windows, in which case they often have Windows carriage returns added into the file, which if on the end of every line can take quite a lot of time to remove!
If you’re using vim there is a quick command search and replace you can do to get rid of these, first you need to be in vim mode and hit the : key and type the below :
%s/^M//g
The only thing to be aware of with this is to not simply type ^M – you need to generate that special character by using the key combination of CTRL-V and then CTRL-M. This will generate the Windows carriage return for you. Once you have done that, finish the command and hit enter and all of the Windows carriage returns will be gone. Allowing you to continue to edit your file without worrying about the syntax errors which they will no doubt cause further down the line.