Remove CR as end of line marker with dos script

Posted on 2006-03-30
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?
Question by:calju
    LVL 30

    Expert Comment

    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,

    Author Comment

    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 |
    LVL 30

    Accepted Solution

    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)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
    Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now