Select Page

Removing ^M From Linux Files

Author: Christian Screen | | January 20, 2012

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

:%s/^V^M//g
 

References

  • http://thedaneshproject.com/posts/how-to-remove-m-character-with-vi/

Oracle BI Publisher (BIP) Tips: Functions, Calculations & More

Check out these BI Publisher tips including functions & calculations so you can understand more about the production and support of BI Publisher reports.

Sherry Milad | January 15, 2018

How to Index a Fact Table – A Best Practice

At the base of any good BI project is a solid data warehouse or data mart.

Christian Screen | March 16, 2010

Qlik vs. Tableau vs. Power BI: Which BI Tool Is Right for You?

Tableau, Power BI, and Qlik each have their benefits. What are they and how do you choose? Read this blog post for a quick analysis.

Tom Hoblitzell | June 6, 2019

Subscribe to Our Blog

Never miss a post! Stay up to date with the latest database, application and analytics tips and news. Delivered in a handy bi-weekly update straight to your inbox. You can unsubscribe at any time.

Work with Us

Let’s have a conversation about what you need to succeed and how we can help get you there.

CONTACT US

Work for Us

Where do you want to take your career? Explore exciting opportunities to join our team.

EXPLORE JOBS