We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now


Remove CR as end of line marker with dos script

calju asked
Medium Priority
Last Modified: 2008-01-09
I have a file and each file have in the end CRCRLF end or line marker. I have to remove CR to have file in windows format (leave CRLF). How is it possible to do with MS Dos bat file?
Watch Question

Top Expert 2007

I created the following batch file that should do the trick:

@echo off

if "%~1"=="" echo Please enter file name.&goto :EOF
if not exist "%~1" echo %~1 does not exist.&goto :EOF

for /f "tokens=1,* delims=:" %%a in ('findstr /N /V _DONOTFIND_ "%~1"') do call :PROCESS "%%b"

goto :EOF


if "%~1"=="" (echo.) else (echo %~1)

If you named the file REMOVECR.BAT and your input file name was input.txt, you could say:

removecr input.txt >output.txt

The results would be placed in output.txt.

Good Luck,


If I put inside file like this then only thing I'm getting out is: COMMENT:TEXT=

COMMENT:TEXT="          TNK   "Y COMMENT:TEXT="Sales Receipt 29-MAR-2006                "Y

COMMENT:TEXT=""> SALE:NAME="TICKET ";AMOUNT=         100.00 ;TAXPERCENTS=0| COMMENT:TEXT=""| COMMENT:TEXT=""; COMMENT:TEXT="Signature_______________________________"| COMMENT:TEXT=""| COMMENT:TEXT="Booking: 5425726          "| COMMENT:TEXT="30.03.2006 12.26-HP1268931"| COMMENT:TEXT=""| TENDER:TENDERID="Cash";NAME="sk.nauda";AMOUNT=         100.00 |
Top Expert 2007
That is a little tricky. How about this:

@echo off

setlocal enabledelayedexpansion

if "%~1"=="" echo Please enter file name.&goto :EOF
if not exist "%~1" echo %~1 does not exist.&goto :EOF

for /f "tokens=1,* delims=:" %%a in ('findstr /N /V _DONOTFIND_ "%~1"') do (
  if "%%b"=="" (echo.)
  else (
    set line=%%b

    if /i "!line:~-1,1!" GEQ " " (echo !line:~0,-1!) else (echo %%b)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.