batch file - Modifying a .bat script to add a bit of text of my choosing to the output -
i posted question part of code further down , got brilliant response helped me solve problem. there bit of debate validity of code below moment works me , concerns in free time.
@echo off >nul find "var want_spring_aid_file_update = 1;" "input.txt" && ( >>output.txt ( /f usebackq^ tokens^=2^ delims^=^" %%a in ( 'findstr /c:var front_spring_aid_file = ^"part_name1^"; "input.txt"') echo %%a ) ) the problem needed solve code probe text file presence of string , based on result grab or not string between double quotes specific line of same text file , drop in new text file. now, title explains, add bit of text of choosing output.
basically have following code in input text file:
var want_spring_aid_file_update = 1; var front_spring_aid_file = "part_name1"; var rear_spring_aid_file = "part_name2"; my current script checks if string in first line present , if probe second line , grab string between "" , drop in new text file.
how can add bit of text of choosing on same line? if outputs part_name1 how can add the model updated part that?
based upon , previous related question, how following work you?
@echo off set "fi=input.txt" set "vm=var want_spring_aid_file_update " set "fm=var front_spring_aid_file " set "sm=var rear_spring_aid_file " set "fo=output.txt" set "so=the model updated part" /f "tokens=2delims==;" %%a in ( 'find /i "%vm%"^<"%fi%"') set/a vd=%%~a 2>nul if not "%vd%"=="1" exit/b >"%fo%" ( /f tokens^=2delims^=^" %%a in ( 'findstr/ilc:"%fm%" /c:"%sm%" "%fi%" 2^>nul') echo %so% %%a) it retrieves 2 values required, if value of want_spring_aid_file_update 1.
[edit] - (tested win7)
here entire content of input.txt:
// commented line var want_spring_aid_file_update = 1; var front_spring_aid_file = "part_name1"; var mid_spring_aid_file = "part_name1.5"; var rear_spring_aid_file = "part_name2";
and output.txt:
the model updated part part_name1 model updated part part_name2
Comments
Post a Comment