removing ^m from files
I work a lot with content uploaded and authored on windows machines and I often get files littered with those ^M's.
I used to use this:
tr -d '\015' < in-file > out-file
but this works nicely in vi:
In command mode:
1,$s/^M//g
The ^M in the substitution above is typed as Ctrl-V Ctrl M.
Comments
Andy,
#!/usr/local/bin/perl # ctrlm.pl infile > outfile while (>) { $_ =~ s/\cM\n/\n/g; print $_; }works a treat as well.
Posted by: Gareth | February 23, 2004 03:26 PM
dos2unix
http://linuxcommand.org/man_pages/dos2unix1.html
Posted by: MartyMC | February 23, 2004 04:07 PM
I saw that mentioned once before, but I never seem to have it on any box I am on.
Posted by: Andy | February 23, 2004 04:10 PM
If you really want a perl version then:
perl -pi -e 's/\015\012/\n/g' filename
Posted by: Tony Bowden | February 23, 2004 11:14 PM
Your VI editor can do this for you. In Vi command mode, to convert a file to unix format, type :-
:set ff=unix
and save the file.
To convert a file to DOS format, type :-
:set ff=dos
Posted by: Duggie | February 24, 2004 12:02 PM
My god there is a lot of clever people that read this blog.
I must post more nerdy stuff, so I can tap into all these ideas.
TIMTOWTDI
Posted by: Andy | February 24, 2004 12:29 PM
% does an operation on every line in a file. In this case, %s/^M//g would do what you want, saving a few keystrokes (not that it matters much, just a bit handier).
Posted by: Russell | February 25, 2004 03:35 PM