Hi, I have tried the below script to remove the carriage return from the end of line from a text file.after executing the script it displays only the last record in the file.
can anyone help me on how to get all the records with the CR removed at the end of line.
@echo off
SetLocal DisableDelayedExpansion
for /f "tokens=*" %%a in ('find /n /v "" ^< "old_file.txt"') 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
) > "new_file.txt"
Thanks,
Sam
"rem "set /p" won't take "=" at the start of a line...."
There's the problem with batch. It is truly unfortunate that MS never added a switch to force "echo" to leave off the trailing cr/lf. There's no way that I know of to avoid this problem without compromising the source data in the output. On top of that, you might still have problems with > and < in the input stream. Highly recommend another approach. Here is a vbscript method:
'begin vbscript "nocrlf.vbs"
set fso=createobject("scripting.filesystemobject")
wscript.echo replace(fso.opentextfile(wscript.argunents(0)).readall,vbcrlf,"")
' end vbscriptImplementation (batch or commandline):
cscript /nologo nocrlf.vbs INPUTFILENAME [> OUTPUT-RESULTS-FILE]I minimized it to make it look cool, but it should probably have some error-checking to see if there's an argument, and an alternative (stdin, or msgbox query) if not.
message edited by nbrane
nbrane, Thanks for your reply, i tried your code but it is not eliminating the CR/LF .
original file:
4SVÇHELLOÇ3AÇODOA
4FOÇPROGRAMÇ3NPÇODOAAfter Running the script:
4SV€HELLO€3A€ODOA
4FO€PROGRAM€3NP€ODOAthe delimiter has changed in the new file
what i really want is:
4SVÇHELLOÇ3AÇOA
4FOÇPROGRAMÇ3NPÇOA
@echo off & setlocal EnableDelayedExpansion set /P line=< "input.txt" type nul > "output.txt" for /F "skip=1 delims=" %%i in ('type "input.txt"') do ( set /P line=!line!%%i< nul ) >> "output.txt"
I'm lost, at this point. This:
original file:
4SVÇHELLOÇ3AÇODOA
4FOÇPROGRAMÇ3NPÇODOA
new file
4SV€HELLO€3A€ODOA
4FO€PROGRAM€3NP€ODOAthe delimiter has changed in the new file
what i really want is:
4SVÇHELLOÇ3AÇOA
4FOÇPROGRAMÇ3NPÇOASo, I take it to mean that "0D0A" (literal, not binary) needs to be replaced by "0A"? If so, that's a "whole new world". "ODOA" does not a binary crlf make. 0D0A is a hexadecimal notation of crlf, rendered into ascii. I guess if I am to be any help at all, I need an exact copy of the test file (no sensitive data, just your working test material). Make a test file, as it appears you have already done. don't change anything. Send it over in pmail or post it here verbatim. Since my language is us/English, and I'm "code-page" challenged, I am probably not much use anyway, but I'll work with what I can to help. Meanwhile, in case I guessed correctly, maybe try this:
set fso=createobject("scripting.filesystemobject")
wscript.echo replace(fso.opentextfile(wscript.argunents(0)).readall,"0D0A","OA")message edited by nbrane
ODOA represents the hexadecimal notation of crlf. I want cr to be removed from the newfile. Here is the sample data in the test file
4SVÇHELLOÇ3AÇ
4FOÇPROGRAMÇ3NPÇ
Have you tried the script I suggested in post #3? Please at prompt type CHCP and post the number reported. There is a problem with language dependent characters that are handled differently in ANSI (Windows) and ASCII (commabd prompt).
Hi IVO, We're having an epidemic of 'OP ignores reply'.
=====================
I copied the sample file into Notepad then saved it as Unicode. At prompt type sample.txt > input.txt then I executed my script in post #3: the output by type output.txt is perfect in console window. If you want it in Notepad window at prompt type
cmd /U (C type output.txt > UNIout.txt
(name as you like) and you are done (coded in UNICODE).