Solved Removing Carriage Returns from a TextFile

September 19, 2011 at 08:27:14
Specs: Windows XP

Reposting this in the correct forum.

I wrote a program that creates a textfile to be imported by a third party. I need to deploy my program to several machines and the problem I'm having is that the third party rejects my textfile because there are carriage returns and line feeds (0D 0A) at the end of every line. With all the stuff I've read, this appears to be the Windows standard. What I need to do is write a batch file that my program will call to strip out the carriage returns (0D) from all lines in my textflie. Because I need to deploy this to several machines and don't want to install extra software on all these machines to accomplish this, is there a command in DOS that will allow me to do this?


See More: Removing Carriage Returns from a TextFile

Report •

September 19, 2011 at 10:16:12
✔ Best Answer
With all the stuff I've read, this appears to be the Windows standard.
Correct! POSIX uses just a new line (\n). Apple chose to use just a carriage return (\r), but then they made OS X, which is based off of FreeBSD. So now they use just a \n. Windows uses both (\r\n) because it copied MS-DOS, which used both. MS-DOS used both because it copied CP/M, which used both. CP/M used both because the teletype typically used with CP/M required both. [As an aside, CP/M used the forward slash (/) for command line switches. This is why Window's path separator is the back slash (\).] And that's your history lesson for the day.

If you're using a Windows program, and it doesn't support \r\n for new lines, it is a buggy program and you should complain until the vendor/programmer fixes it.


Const filePath = "out.txt" '"A:\directory\leading\to some\file.ext"

Set fso = CreateObject("Scripting.FileSystemObject")
fileText = fso.OpenTextFile(filePath).ReadAll
fso.OpenTextFile(filePath, 2, True).Write Replace(fileText, vbCr, "")

How To Ask Questions The Smart Way

Report •

September 27, 2011 at 07:56:50
Good read. Thanks for the info!

Report •

Related Solutions

Ask Question