Computing.Net > Forums > Disk Operating System > Batch file to create/edit text file

Batch file to create/edit text file

Reply to Message Icon

Original Message
Name: gnitelady
Date: February 13, 2002 at 10:06:39 Pacific
Subject: Batch file to create/edit text file
Comment:

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?


Report Offensive Message For Removal

Response Number 1
Name: Secret_Doom
Date: February 13, 2002 at 20:41:58 Pacific
Subject: Batch file to create/edit text file
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 2
Name: Mick
Date: May 7, 2002 at 03:28:11 Pacific
Subject: Batch file to create/edit text file
Reply: (edit)

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.


Report Offensive Follow Up For Removal

Response Number 3
Name: Mick
Date: May 7, 2002 at 04:20:46 Pacific
Subject: Batch file to create/edit text file
Reply: (edit)

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.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch file to create/edit text file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software