Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need to create a batch file to which I can pass 2 parameters to create, type and save a text file. Edit and copy con require additional keystrokes outside the batch file. Is there a way to create and edit a text file in batch without user intervention?

Yes, there is.
Let me see if I've understood it:
You have a script, and you pass two parameters to it:script.bat string1 string2
Then you want it to create a text file with:
=== Textfile begin ===
string1
string2=== Textfile end ===
Is that it?
If YES, here it goes:
@echo off
if "%2"=="" goto eof
echo %1> file.txt
echo %2>> file.txt
:eof
We don't need to hardcode the filename. In the following script, the first parameter is the filename, and the second and third are the strings:
@echo off
if "%3"=="" goto eof
echo %2>%1
echo %3>>%1
:eof
Was that really what you were looking for?-- Secret_Doom - Leonardo Pignataro --
secret_doom@hotmail.com
www.batch.hpg.com.br

I used the Edlin command which allows you to edit text. It is very rudamentary though. I've been able to get Edlin to crop all lines of text above and below the line that I wanted to save in a text file from a bat file, however I can't crop individual characters. Syntax is tricky. Edlin is old and has few commands.

To use Edlin you need to call it from your batch program like this:
EDLIN EXAMPLE.TXT < INPUT.ED
where EXAMPLE.TXT is your text string. INPUT.ED is a file which you must create. Just make a new text document and rename it INPUT.ED. INPUT.ED contains all the text editing strokes that you want performed on your string/s. Enter your series of commands and save INPUT.ED into the same directory as your BAT file.

![]() |
dos6.22 upgrade disks
|
DOS Prompt
|

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