Hello, 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?
Thanks.
It's *almost* possible, but lines that start with "=" must be changed(I added a space before the "=" in the below script). Replace "oldfile" and "newfile" to your filenames:
@echo off SetLocal DisableDelayedExpansion for /f "tokens=*" %%a in ('find /n /v "" ^< "oldfile"') do ( set line=%%a SetLocal EnableDelayedExpansion set line=!line:*]=! rem "set /p" won't take "=" at the start of a line.... if "!line:~0,1!"=="=" set line= !line! rem there must be a blank line after "set /p" rem and "<nul" must be at the start of the line set /p =!line!^ <nul endlocal ) >> "newfile" pause
Might open it in notepad and then save it. Notepad ought to strip that off. 1/3 of highway deaths are caused by drunks. The rest are by people who can't drive any better than a drunk.
Thanks for the post. That did not seem to do anything however. I've read some other posts to create a batch file with the following code: for /f "tokens=* delims=" %i in (abc.txt) do (
echo %i >> abc.txt
)I'm using Windows XP and all this seemed to do was add a space after my line:
Note: 0D = carriage return
0A = line feedOriginal line: Hello World!0D0A
After running batch file: Hello World! 0D0A
What I really want is: Hello World!0A
It's *almost* possible, but lines that start with "=" must be changed(I added a space before the "=" in the below script). Replace "oldfile" and "newfile" to your filenames:
@echo off SetLocal DisableDelayedExpansion for /f "tokens=*" %%a in ('find /n /v "" ^< "oldfile"') do ( set line=%%a SetLocal EnableDelayedExpansion set line=!line:*]=! rem "set /p" won't take "=" at the start of a line.... if "!line:~0,1!"=="=" set line= !line! rem there must be a blank line after "set /p" rem and "<nul" must be at the start of the line set /p =!line!^ <nul endlocal ) >> "newfile" pause
Judago, Thanks for the reply. When I try your code, I'm getting this error:
%%a was unexpected at this time.When I remove one of the "%" so it reads %a, then I get some data in my new text file that removes the CR but it prints: !line!
...instead of my "Hello World"
Thanks.
It's meant to be run as a .bat script, not be run individually from the command line. The differences in parsing cause the problem you mentioned.
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |