Specialized IT Services focused on Data Management | Speak with Us 877-634-9222
Art of BI: Removing ^M From Linux Files
I was at a project recently where someone had updated several Linux config/text files using a Windows machine.
They FTP‘d the files to their desktop, used notepad or something similar to make the edits, and then FTP’d the file back to the Linux server thinking that all would work swimmingly. Unfortunately they overwrote the original files when they uploaded the files back to the Linux server.
As you know when this happens, Linux can recognize these foreign line breaks and places a nasty ^M at the end of each break as it interprets it as an actual character. This renders most config files, especially a XML based config file, useless for parsing by the program trying to read the file.
The solution is regular expression based and looks kinda funky but it works.
Basically open the file in question using the VI editor. Hit the colon command to start the menu input and enter the expression below against the file.
:%s/[ctrlkey+v and ctrl-key+M]//g
which will give you