Batch script – replace string for another string from received from variable

greetings.

I have this batch script which has the objective of retrieving a URL from an input, save it to a variable. Then this URL should have a part of it, a 3-4 letters string replaced by another string which is inside a list in a file (lista.txt). Then, the script should open the Chrome browser and one tab for each new URL generated by the string replacement. I understand there are several other ways to do that, but I intend to keep using the batch file and check where my mistake is. The script seem to be working until I get to the point where the string replacement by another string coming from a variable. This is the script:

@echo off
set BROWSER=chrome.exe
set /p URL=Type the URL:
echo.
for /f %%i in (Lista.txt) do (
    set URL=%%URL:%IBOV%=%i%%
    echo %URL%
    START %BROWSER% -new-tab "%URL%"
)
Pause

_contents of lista.txt:

IBOV GNDI3 USIM5 OIBR3 MEAL3 ETER3 COGN3 TASA4 BBDC4 ITUB4 SUZB3 VALE3 PETR4 RAIL3

end of lista.txt



Read more here: https://stackoverflow.com/questions/64901137/batch-script-replace-string-for-another-string-from-received-from-variable

Content Attribution

This content was originally published by Felipe Araujo Borges at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: