Home ›
Remove ^M from the end of all lines in a file that some fool edited with a Windows programRemove ^M from the end of all lines in a file that some fool edited with a Windows program
Submitted by Benjamin Melançon on April 4, 2010 - 4:54pm
Searched words:
remove ^M
vi Ubuntu
control M
Where foo is the file that has the control Ms:
cat foo | col -b > foo2; mv foo2 foo
For instance, to take a likely Drupal example:
cat page.tpl.php | col -b > page.tpl.php.fixed; mv page.tpl.php.fixed page.tpl.php
Alternately, to do a bunch of files at once, use the *nix find command and the more convenient one-command dos2unix line ending changer via the tofrodos package.
Install the prerequisites first if you need to:
sudo apt-get install tofrodos
Then run the command, this one runs only for CSS files:
find . -type f -name "*.css" -exec dos2unix "{}" \;
More like this
- Approaches to in-line editing with a few different JavaScript front-end frameworks
- Sadly, some brilliant text had to be jettisoned from the Definitive Guide. Some of it lives here.
- Disabling or moving node/add/[content-type] links from beneath "Add content" in the navigation menu also removes them from the Add content page (node/add)
- Undo a git add - remove files staged for a git commit
- Fix messy Mac-style line endings to have proper Unix text file format


Comments
Post new comment