[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Remove CR as end of line marker with dos script

Posted on 2006-03-30
3
Medium Priority
?
598 Views
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?
0
Comment
Question by:calju
  • 2
3 Comments
 
LVL 30

Expert Comment

by:SteveGTR
ID: 16332032
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

:PROCESS

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,
Steve
0
 

Author Comment

by:calju
ID: 16332104
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 |
0
 
LVL 30

Accepted Solution

by:
SteveGTR earned 2000 total points
ID: 16332859
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)
  )
)
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

834 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