I have a text file called Test.OPT with the below contents:
REPORTLOG +"E:\LicenseLogs\cstd.rl"
GROUPCASEINSENSITIVE ON
GROUP TEST_USERS user1 user2
INCLUDE feature1 TEST_USERS
INCLUDE feature2 TEST_USERS
INCLUDE Solver_feature3 TEST_USERS
INCLUDE Solver_feature4 TEST_USERS
INCLUDE Solver_feature5 TEST_USERS
INCLUDE Solver_feature6 TEST_USERS
INCLUDE Solver_feature7 TEST_USERS
I want to append to end of the line containing GROUP TEST_USERS the string User3 in above text file.
I have below a batch file which does not work as expected:
@echo off
setlocal EnableDelayedExpansion
set search=%1
set "textfile=D:\testing\Test.OPT"
set "newfile=D:\testing\TestTemp.OPT"
(for /f "delims=" %%i in (%textfile%) do (
set "line=%%i"
findStr /B /c:"GROUP TEST_USERS" %%i>nul && (
set line=%%i %search%
) || (
set "line=%%i"
)
echo(!line!
endlocal
))>"%newfile%"
I could do this easily in Java, but due to some reason I'm forced to do this with a batch script.
findStr /B /c:"GROUP TEST_USERS" %%itries to find the string in a file named%%i. You wantecho %%i|findstr /bc:"GROUP TEST_USERS"