Solved: Remove the ^M Character

Post Reply
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

Solved: Remove the ^M Character

Post by mister_v »

Hi,

I have some problems with whitespace characters in a txt document.
I have converted the newline characters \n\r but still have some problems with whitespace.

It is identified by ^M.
How do i get rid of it?

Thanks,
chris
Site Admin
Posts: 194
Joined: Mon Jul 21, 2008 9:52 am

Re: Remove the ^M Character

Post by chris »

When you move files from windows to (l)unix, you always have problems with white characters.
Thats because windows and linux handle with spaces differently.

Sed can be found on most linux/unix distributions.

Code: Select all

sed s/\r// hello.txt > goodhello.txt
you can also do the same with perl:

Code: Select all

perl -pie 's/\r//g' hello.txt > goodhello.txt
probably the easiest way is dos2unix,

Code: Select all

dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...]
Let us know if it works.
mister_v
Posts: 188
Joined: Thu Mar 04, 2010 9:19 pm

Re: Remove the ^M Character

Post by mister_v »

Code: Select all

sed s/\r// hello.txt > goodhello.txt
works fine,

Thanks
Post Reply