Computing.Net > Forums > Disk Operating System > Ignoring CTRL+Z character in batchfile

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Ignoring CTRL+Z character in batchfile

Reply to Message Icon

Name: Secret_Doom
Date: March 12, 2001 at 16:27:29 Pacific
Comment:

Hi all!
I'm a edlin user. I use it very very often in my batch files.

The problem is: in edlin, you edit a file with an another file.
(ie: edlin text.dat " command. BUT: edlin uses the ^Z character! And it's interpreted in a batch file as a end-of-file character.
So I can't do a "echo blabla^Zlala > txt.txt" ...

>> Is there a way forcing the batch file to ignore ^Z characters?? Maybe something regarding command.com... I don't know. Any help would be welcome!!!! > <<) :-D

email: secret_doom@hotmail.com



Sponsored Link
Ads by Google

Response Number 1
Name: Laurence
Date: March 12, 2001 at 20:57:18 Pacific
Reply:

I'm not sure I understand what you mean, but here is an edlin batch I use regularly which may be of help.


:: replac.bat
@ECHO off
IF not "%3"=="" GOTO start

:help
ECHO.
ECHO %%1 is target file
ECHO %%2 is text to replace
ECHO %%3 is replacement text
ECHO.
ECHO Examples:
ECHO replace test.txt A a : replaces A with a
ECHO replace test.txt color colour : replaces color with colour
ECHO replace test.txt Y N : replaces Y with N
ECHO.
ECHO File to be changed must be in current directory, which
ECHO must be writeable. Filename only; no colon or backslash.
ECHO.
GOTO end

:start
ECHO %1 |FIND ":" >nul
IF not errorlevel 1 ECHO colon or backslash not allowed
IF not errorlevel 1 GOTO help
ECHO %1 |FIND "\" >nul
IF not errorlevel 1 ECHO backslash or colon not allowed
IF not errorlevel 1 GOTO help
IF not exist %1 ECHO "%1" not in current directory
IF not exist %1 GOTO help
REM Create an empty script file >%temp%.\replc.scr
FOR %%v in (f100LFF''20 l102 w q) do ECHO %%v>>%temp%.\replc.scr
:: text to be replaced follows immediately after 'R' below
ECHO 1,R%2> %temp%.\part1.txt
:: the following adds two spaces to the front of part1.txt,
:: thus pushing the CR/LF off the end.
:: this works becuase EDLIN.exe ignores leading spaces
IF exist %temp%.\part1.txt DEBUG.exe %temp%.\part1.txt nul
DEL %temp%.\replc.scr > nul
IF exist %temp%.\ctrlz.dat DEL %temp%.\ctrlz.dat > nul
:: this creates a 1 byte file with Ctrl-Z in it
ECHO E| EDLIN.exe /B %temp%.\ctrlz.dat>nul
IF exist %temp%.\part2.txt DEL %temp%.\part2.txt
:: replacement text with follows after 'ECHO ' below
ECHO %3>%temp%.\part2.txt
ECHO e>>%temp%.\part2.txt
COPY /B %temp%.\part1.txt+%temp%.\ctrlz.dat+%temp%.\part2.txt %temp%.\edscr.txt >nul
EDLIN.EXE %1 nul
:: This deletes the EOF character which was added at the end
::
COPY/B/Y %1/A+,, . % Place a '>nul' here to supress screen output%
::DEL %temp%.\%1
DEL %temp%.\ctrlz.dat
DEL %temp%.\edscr.txt
DEL %temp%.\part?.txt

:end

Batfiles: The DOS batch file programming handbook


0

Response Number 2
Name: Laurence
Date: March 12, 2001 at 20:58:28 Pacific
Reply:

Watch for line wrapping!


0

Response Number 3
Name: Secret_Doom
Date: March 14, 2001 at 16:11:53 Pacific
Reply:

Hi. Thanks for your reply.
I didn't understood some parts of it (and it didn't work! -- it stops on debug command)

Well, I guess the copy command ("COPY /B %temp%.\part1.txt+%temp%.\ctrlz.dat+%temp%.\part2.txt %temp%.\edscr.txt >nul") gets the text to be replaced (with an 1,r), an ^Z, the replacing text and an e character that commands edlin to exit. Ok, all that to make this line into one file:

1,rstring1^Zstring2
e

But that copy command with + places the contents of files in different lines, like this:

1,rstring1
^Z
string2
e

That's what I didn't get! May you explain me how to make copy command to put contents of files all in the same line?

Thanks again.

Secret_Doom


0

Response Number 4
Name: Laurence
Date: March 16, 2001 at 01:37:17 Pacific
Reply:

That replac.bat works perfectly for me.
I hope you're not using NT! Practically
nothing works (or works right) in NT.

There are many methods to do what you want,
and I am presently under severe time constraints. My best suggestion is to ask in new:alt.msdos.batch . That is where the batch experts hang out.


0

Response Number 5
Name: Secret_Doom
Date: March 16, 2001 at 18:10:17 Pacific
Reply:

Hi, Thanks for pointing me that place.
But I didn't understand that adress!

Is that a news adress? Like to use on outlook express or something? I did tryed it, (with server alt.msdos.batch), but didn't work

Please, tell me what does that means, I'm really interested


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Ignoring CTRL+Z character in batchfile

Reading data from within a batch file www.computing.net/answers/dos/reading-data-from-within-a-batch-file/7100.html

works on string in a batch file www.computing.net/answers/dos/works-on-string-in-a-batch-file/6835.html

.bat file www.computing.net/answers/dos/bat-file/6774.html