1.

Solve : Batch to batch?

Answer»

I was wondering if there was any way to make a BATCH file modify another batch file? (i.e. add another line of commands to a certain line in a batch file using a different batch file) Either that or how to make a batch file read commands from a text file. (i.e. in text file it says "start test.txt" (w/o quotes) and the batch file reads that from the text file and executes it.)

Thanks for the help!Using redirection in a batch file can append data to another file. Text files cannot be modified in place, modifying individual records in a text file requires both an input and output stream. Yes it can be done in batch but it's not pretty. Better left to scripting and programming languages.

Quote

Either that or how to make a batch file read commands from a text file. (i.e. in text file it says "start test.txt" (w/o quotes) and the batch file reads that from the text file and executes it.)

You'd have to read the line, parse it, then execute it. Really need to see the specific data.

Why are you using batch code for these TASKS?

Normal edit like notepad is imposible but you can somethink like this

@echo off
set /p name=Select name:
copy con >%name%.bat

or

@echo off
set /p name=Select name:
:A
if exist %name%.bat type %name%.bat
set /p input=Type your code:
echo %input% >%name%.bat
goto A

To read text.txt and execute "start test.txt"

@echo off
for /f "tokens=1-3 delims= " %%x in (text.txt) do %%x %%y

If something is wrong note that i write this post on cellphone SECOND solution worked perfectly! Thanks! But I don't know if you understood what I meant by the reading the text file and executing it. I might have worded it strangely, but what I meant was in my text file is something like:

@echo off
start whatever.bat

And I was wondering how to run those commands from text files? But again, thanks for the solution to the batch edit!Ok i think i undestood that. Mabey copy txt file to .bat file and use call command? There must be other way but i cant help u right nowOk thanks that worked perfectly!One more question. How do I pull out just a small snippet from a txt file and use it as a variable? Like lets say I want to ping a website, then output the feedback of it into a txt file, then pull just the IP of the website out of that txt file and use the IP address as a variable so I can use the same batch without EDITING for different webpages? LOL i've been trying to find a solution but the 'for' command only seems to be reading only the last line of text.ok got it to make txt a variable, but I need one more thing, how can I replace the last line of text in a txt document with something else? I only need to raplace the last line, anything more and it will mess it up. ThanksQuote from: dragonmaster2091 on January 30, 2008, 02:53:58 PM
ok got it to make txt a variable, but I need one more thing, how can I replace the last line of text in a txt document with something else? I only need to raplace the last line, anything more and it will mess it up. Thanks
download GNU sed for windows here. Then on the command line or batch file
Code: [Select]C:\test>type file.txt
A,B,C,D,E,F,G
this is last line
C:\test>sed -e "$d;s/$/\nnew last line/" file.txt
A,B,C,D,E,F,G
new last line



Discussion

No Comment Found