I\'d like to search for a list of words from an external list (simple each word on a line) which we\'ll call "List.txt", and search for them in a file (C:\\Users\\P Di
@echo off
setlocal EnableDelayedExpansion
REM INITIALIZE THE LIST OF WORDS THAT WILL BE SEARCHED
set targetWords=:EOF
rem I'd like to search for a list of words from an external list (simple each word on a line)
for /F %%a in (List.txt) do (
rem and search for them in a file (C:\Uses\P Ditty\Documents\SH3\data\cfg\Backups_SCR*.clg)
findstr "%%a" "C:\Uses\P Ditty\Documents\SH3\data\cfg\Backups_SCR*.clg" > NUL
rem if they are there...
if !errorlevel! equ 0 (
REM INSERT THE WORD IN THE TARGET LIST
set targetWords=!targetWords! %%a
)
)
REM INSERT THE END-OF-FILE MARK IN THE FILE
echo :EOF>> Campaign_SCR.mis.tmp
REM INITIALIZE THE NUMBER OF LAST PROCESSED LINE IN REDIRECTED Campaign_SCR.mis.tmp
set lastLine=0
rem ... find those words on another file(Campaign_SCR.mis.tmp)
< Campaign_SCR.mis.tmp (for /F "delims=:" %%a in ('findstr /N "%targetWords%" Campaign_SCR.mis.tmp') do (
REM DUPLICATE PREVIOUS LINES UNTIL NEW TARGET LINE
set /A numOfLines=%%a-lastLine-1
for /L %%i in (1,1,!numOfLines!) do (
set line=
set /P line=
echo(!line!
)
rem if the line starts with "Name="
set /P line=
if "!line:~0,5!" equ "Name=" (
rem replacing the whole line...with Name=ShipDummy
echo Name=ShipDummy
rem After that the two lines below that in that same file would be replaced with 2nd line "Class=ShipDummy",
set /P line=
echo Class=ShipDummy
rem then 3rd line "Type=206".
set /P line=
echo Type=206
set /A lastLine=%%i+2
) else (
REM DUPLICATE THE NON MATCHING LINE, IF IS NOT THE :EOF MARK
if "!line!" neq ":EOF" (
echo !line!
set lastLine=%%i
)
)
)) > Campaign_SCR.mis.tmp.NEW
REM UPDATE THE NEW FILE
REM del Campaign_SCR.mis.tmp
REM ren Campaign_SCR.mis.tmp.NEW Campaign_SCR.mis.tmp