Page 1 of 1

Solved: Remove the ^M Character

Posted: Fri Sep 03, 2010 3:11 am
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,

Re: Remove the ^M Character

Posted: Fri Sep 03, 2010 10:09 am
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.

Re: Remove the ^M Character

Posted: Fri Sep 03, 2010 12:34 pm
by mister_v

Code: Select all

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

Thanks