0

I have tried this and it isn't working...:

@echo off
echo seting up session...
setLocal EnableDelayedExpansion
type command1.txt > session.html
for /f "tokens=* delims= " %%a in (command2.txt) do (
set /a N+=1
set v[!N!]=%%a
)
set line1=%v[1]%

echo %line1%

endlocal
)

REM -- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION

::BatchSubstitude - parses a File line by line and replaces a substring"
::syntax: BatchSubstitude.bat OldStr NewStr File
::          OldStr [in] - string to be replaced
::          NewStr [in] - string to replace with
::          File   [in] - file to be parsed
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
    set "line=%%B"
    if defined line (
        call set "line=echo.%%line:%~1=%~2%%"
        for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
    ) ELSE echo.
)
start session.html
echo done! Enjoy!
pause

What I am trying to do is:

<p><b>This is a Simulated Media Rendering Session
<br></br></b>Made by MicroTech</p><br></br>Visit us @ mtcomputers.weebly.com<br>     </br>and find SMRS Info @ mtsmrs.weeby.com<br></br>Have fun on the internet!<br></br>Here is Yor Media:</p>
<iframe width="420" height="345"
src="http://www.youtube.com/embed/code"
</iframe>
<p>
http://www.mtcopmuters.weebly.com
</p>

See that scr="http:/.... Thing? I need to change "code" in that line to a variable from a text file (managed above). But the question is: I need to set a variable in my batch file that is equal to the text in command2.txt (already done), then I need to change the word "code" in the above html snippet to whatever is assigned to that variable. On Any answers please describe where I put the file names and everything etc.... Thanks! Have a good day!

1 Answer 1

1

You've expressed it poorly what you want. You want us to be precise by saying " please describe where I put the file names and everything etc...." but you havn't given us a similar courtesy.

Actually, You have pasted together two pieces of code from different places without making a working batch file. For example the first part of the batch file does not contain an exit. The second part is clearly from another batch file. This could be rendered as a subroutine and called:

@echo off
echo setting up session...
setLocal EnableDelayedExpansion
type command1.txt > session.html
for /f "tokens=* delims= " %%a in (command2.txt) do (
    set /a N+=1
    set v[!N!]=%%a
    )
set line1=%v[1]%

echo %line1%
call :BatchSubstitute code %line1% session.html

start session.html
echo done! Enjoy!
pause
:: exit main body
exit /b

:: Start of Subroutines ------
REM -- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION

::BatchSubstitude - parses a File line by line and replaces a substring"
::syntax: BatchSubstitute.bat OldStr NewStr File
::          OldStr [in] - string to be replaced
::          NewStr [in] - string to replace with
::          File   [in] - file to be parsed
:BatchSubstitute
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
    set "line=%%B"
    if defined line (
        call set "line=echo.%%line:%~1=%~2%%"
        for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
    ) ELSE echo.
)
:: Exit Subroutine
exit /b

I hope I managed to guess your desired results properly.....

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.