Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to replace a string on the second line in a text file using a batch file?
    primarykey
    data
    text
    <p>Ok so ive been working on a fairly complex batch file that basicly asks the user to create a text file that contains 6 (or more) lines of text. Then it takes that file and changes every instance of every letter to its respective number (for example if the first line of the text file said "programable" then the program would change all instances of the letter "a" into 1 and "b" into 2 and so on until it was all numbers. It would then read "16 18 15 7 18 1 13 1 2 12 5") and i would do that by using the following script:</p> <pre><code>set /p var=&lt; text.txt set var=%var:a=1% echo.%var% &gt;&gt; text.txt </code></pre> <p>However the only problem with this script is that it will only change the letter a on the first line to 1, not the letter "a" in the rest of the document.</p> <p>I also tried splitting the document at the beginning of the program so that when the user types the text for the first line it sends it to a separate hidden file (text1.txt) instead of just sending all of the lines of text that the user types, into one text file (text.txt)</p> <p>I did so using this:</p> <pre><code>set /p line1=type the first line: echo %line1% &gt;&gt; text1.txt attrib +h text1.txt set /p line2=type the second line: echo %line2% &gt;&gt; text2.txt attrib +h text2.txt :: ######################################################################## :: Im not going to repeat this 6 times but hopefully you get my point :: ######################################################################## </code></pre> <p>Now the problem with splitting the lines into separate files is that it would be in-efficient and extremely time consuming to change all instances of every letter into their respective numbers, and do it for each line (or in this situation, file) that the user inputs... If it would help if i put all this in context, here is the script for my program so far, for the ":LOADING" subscript i am currently using the method i explained earlier where i split the lines into files. </p> <p>Code: (Save As "stringparsing.bat")</p> <pre><code> @echo off title BETA cls echo. echo. echo. echo Setting Variables... echo Loading Language Database... :: ################################################################################### :: CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE CALLING VARIABLE DATABASE :: ################################################################################### :: An Idea i was thinking of trying was to put a subscript here that calls another :: batch file that contains a list of the letters set as variables to their :: respective numbers (example: SET a=1, SET b=2, SET c=3) :: ----------------------------------------------------------------------------------- PING 1.1.1.1 -n 1 -w 3000 &gt;NUL goto MAIN :MAIN set foo=0 cls echo. echo. echo. echo. echo =================================== echo ################################# echo ####### Main Menu: ####### echo ################################# echo =================================== echo. echo. echo 1.) Create New Language File... echo. echo 2.) Load Existing Lanuage File... echo. echo 3.) Settings... echo --------------------------------------------------------- SET /p CHOICE= Select a Function: IF %CHOICE%== 1 GOTO CREATE IF %CHOICE%== 2 GOTO LOAD IF %CHOICE%== 3 GOTO SETTINGS GOTO MAIN :CREATE cls title Step 1 echo. echo. echo. echo echo ============================================================================ echo. set /p name= please type a name for your new language file: echo. echo ================================================================================= cls echo. echo. echo. echo ============================================================== echo ############################################################## echo #============================================================# echo # # echo # - After you hit enter you will be redirected # echo # to a Live Typer. so anything you type into # echo # it will be sent to %name%.txt. # echo # # echo # # echo # - Next, select load language! # echo # # echo #============================================================# echo ############################################################## echo ============================================================== pause goto typer1 :typer1 cls set /p line1= : echo %line1% &gt;&gt; %name%1.txt attrib +h %name%1.txt cls set /p line2= : echo %line2% &gt;&gt; %name%2.txt attrib +h %name%2.txt cls set /p line3= : echo %line3% &gt;&gt; %name%3.txt attrib +h %name%3.txt cls set /p line4= : echo %line4% &gt;&gt; %name%4.txt attrib +h %name%4.txt cls set /p line5= : echo %line5% &gt;&gt; %name%5.txt attrib +h %name%5.txt cls set /p line6= : echo %line6% &gt;&gt; %name%6.txt attrib +h %name%6.txt cls echo. echo. echo. echo ========================================================== echo. ( IF EXIST %name%1.txt echo - FIRST LINE CONFIRMED. IF EXIST %name%2.txt echo - SECOND LINE CONFIRMED. IF EXIST %name%3.txt echo - THIRD LINE CONFIRMED. IF EXIST %name%4.txt echo - FOURTH LINE CONFIRMED. IF EXIST %name%5.txt echo - FIFTH LINE CONFIRMED. IF EXIST %name%6.txt echo - SIXTH LINE CONFIRMED. echo %name% &gt; Language_File.txt attrib +h Language_File.txt set /a foo+ =1 ) echo. echo ========================================================== goto LOAD :LOAD set /a foo+ =1 IF %foo%== 2 goto loadexternal goto LOAD23 :loadexternal echo. echo language file is loading now! pause &gt; nul cls set /p name=&lt;Language_File.txt echo. echo. echo Language_File Loaded! pause &gt;nul goto LOAD23 :LOAD23 cls echo. echo. echo. echo. echo. echo Encoding Your Language File... Please Wait... echo. echo. echo. PING 1.1.1.1 -n 1 -w 3000 &gt;NUL :A1 set /p var=&lt; %name%1.txt set var=%var:a=1% echo.%var% echo %var% &gt; %name%1.txt echo. echo. echo. echo "A" done. goto B1 :B1 set /p var=&lt; %name%1.txt set var=%var:b=2% echo.%var% echo %var% &gt; %name%1.txt echo. echo. echo. echo "B" done. goto C1 :C1 set /p var=&lt; %name%1.txt set var=%var:c=3% echo.%var% echo %var% &gt; %name%1.txt echo. echo. echo. echo "C" done. goto D1 :D1 set /p var=&lt; %name%1.txt set var=%var:d=4% echo %var% &gt; %name%1.txt echo "D" done. goto E1 :E1 set /p var=&lt; %name%1.txt set var=%var:e=5% echo %var% &gt; %name%1.txt echo "E" done. goto F1 :F1 set /p var=&lt; %name%1.txt set var=%var:f=6% echo %var% &gt; %name%1.txt echo "F" done. pause cls type %name%.txt pause &gt;nul goto MAIN :END cls title SHUTTING DOWN... echo. echo. echo. echo Terminating service stream... echo. echo. echo. echo. echo Done! Thank you for using this program! ping 1.1.1.1 w -n 1 -w 6000 &gt; NUL Exit*** </code></pre> <p>If you have a solution i would be glad to hear it because i have been searching high and low for a solution to this problem but have found nothing. Also, if any one notices any other mistakes or errors in my script then please feel free to comment! </p> <p>Thanks in advance!</p> <p>PS. If the last script i posted in this topic didnt come out right or it was all mixed up then just download the script from this link:</p> <p>[http://home.danieljewison.operaunite.com/f/content/Documents/stringparsing.bat][1] </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload