views:

65

answers:

4

Hi,

As described in questions, if I see a file in unix then I see special characters in it like ^M at the end of every line but if I see same file in eclipse than I do not see that special characters.

How can I remove those characters in the file, if am using eclipse for editing the file, do we have to make any specific changes in the eclipse preferences for the same ?

Any guidance would be highly appreciated.

Update:

Yes indeed it was carriage issue and following command helped me to get it sort out:

dos2unix file1.sh>file2.sh and file2.sh will be the file and it will not have any carriage values.

Possibly we can get warning like

could not open /dev/kbd to get keyboard type US keyboard assumed could not get keyboard type US keyboard assumed but following command will suppress the warnings:

dos2unix -437 file1.txt>file2.txt

+1  A: 

They are probably Windows carriage return characters. In Windows, lines are terminated with a carriage-return character followed by an end-of-line character. On Unix, only end-of-line characters are normally used, therefore many programs display the carriage return as a ^M.

You can get rid of them by running dos2unix on the files. You should also change your Eclipse preferences to save files with Unix end of lines.

Avi
+2  A: 

You have saved your text file as a DOS/Windows text file. Some Unix text editors do not interpret correctly DOS/Windows newline convention by default. To convert from Windows to Unix, you can use dos2unix, a command-line utility that does exactly that. If you do not have that available in your system, you can try with tr, which is more standard, using the following invocation:

tr -d '\r' < input.file > output.file
gpeche
@gpeche: tr is not working and `^M` still appears in the file in unix editor, also I have tried dos2unix filename but it also does not work.
Rachel
This command is not working for me, `tr -d '\r` file1.txt > file2.txt`, am just waiting and no outputs.
Rachel
It looks like you have your quotes messed up. They go just around the `\r`
gpeche
A: 

You can remove those using dos2unix utility on a linux or unix machine. The syntax is like this dos2unix filename.

CoolBeans
that's `dos2unix <filename>`. The formatting in the answer didn't make the usage obvious
gpampara
Sorry I was responding from my android on the go. Thanks for pointing it out.
CoolBeans
That makes me think that we need an app for so.
CoolBeans
@Coolbeans: What app are you using for accessing SO on phone ?
Rachel
No app. Just the browser on samsung galaxy S.
CoolBeans
A: 

This are windows new line chars. You can follow steps shown in this post to have correct this issue.

Jaydeep