0

I am reading a ASCII file from LINUX(Debian) into Python CGI script where it is edited via a web page and then saved,

If I use a graphical text editor the edited and un-edited file appear the same and are corectly formatted.

Using vi the edited file contains ctrl M as the EOL marker and all lines rolled into one but the unedited file is correctly formatted. Using :set List in vi to see control characters the edited file remains as described above, but in the unedited file $ appears as EOL marker. I know LINUX EOL is ctrl 0x0D but what is the $?

Why does $ format correctly and ctrl M does not?

eumiro
  • 207,213
  • 34
  • 299
  • 261
Eric Hewett
  • 557
  • 7
  • 16

2 Answers2

1

The $ is displayed by vi (in certain modes). It is not in the file contents. You could use od -cx yourfile to check that.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
1

In vi, the $ matches the EOL character. You can change the EOL character with :set fileformat=XXX as seen here. I'm not 100% sure that if you change the filetype that the $ will match the new EOL as I haven't tried it. But that link contains information that will be handy for the rest of the answer.

The ^M or (CTRL-M) character is roughly equivalent to a carriage return.

From what you're saying, it sounds like the graphical text editor is using Mac-like EOL which is just a carriage return (CR) without the line feed. Hence the ^M characters and all the lines rolled into one. If it was using Windows/DOS EOL, which is carriage return plus line feed (CR+LF), I would expect the ^M characters but each line on it's own separate line.

This answer explains how to get rid of the ^M characters. I wouldn't use dos2unix since I'm not sure how it would handle having just the CR and not CR+LF.

Community
  • 1
  • 1
embedded.kyle
  • 10,976
  • 5
  • 37
  • 56