I am trying to find and replace strings within .dat files (basically text). I have a list of items I need found and the items I need to replace them with. I used a batch script I found online, which worked yesterday but doesn't work today! If anyone can help with this ASAP I am in desperate need of help very quickly.
"Find" "Replace"
"MAW01_Fugro_2018" "MAW01_BSW_Fugro_2018"
" " "_"
"Proc-R3" "Proc-R4"
"Proc-R2" "Proc-R3"
"Proc-R1" "Proc-R2"
"Proc/" "Proc-R1/"
"_FixedNav/" "/"
"_RAW_" "_"
"_ 0" "_0"
"X3618_01B_Proc-R1"
"X3622_001_Proc"
"X3622_001_01B_Proc"
"M3382_01A_Proc-R1"
"3600G_INFILL_01B_Proc-R1"
"M3485_001_01A_Proc"
"__" "_"
"RR_02ABC_Proc-R2" "RR_02ABC_Proc-R1"
"RR_02ABC_01_Proc-R2" "RR_02ABC_01_Proc-R1"
"RR_02D_01_Proc-R2" "RR_02D_01_Proc-R1"
"RR_02D_Proc-R2" "RR_02D_Proc-R1"
"RR_02E_Proc-R2" "RR_02E_Proc-R1"
"RR_02F_Proc-R2" "RR_02F_Proc-R1"
Here's the thing: I need to run this on about 20 files, but not all files I want to run this on will have every string within it. I need the script to find the string and replace, and if thee string does not exist, then don't do anything. Also, the string's must match EXACTLY to the ones in Quotes in order to replace.
Below is the batch file I found online, and basically copied and pasted for each string I needed to replace. (AGAINNOT WORKING TODAY, SAYING CANNOT FIND _.vbs, even though this worked last night!!!)
Code: Select all
setlocal
call :FindReplace "Find" "Replace" File.dat
exit /b
:FindReplace <Find> <Replace> <file.dat>
set tmp="%temp%\tmp.txt"
If not exist %temp%\_.vbs call :MakeReplace
for /f "tokens=*" %%a in ('dir "%3" /s /b /a-d /on') do (
for /f "usebackq" %%b in (`Findstr /mic:"%~1" "%%a"`) do (
echo(&Echo Replacing "%~1" with "%~2" in file %%~nxa
<%%a cscript //nologo %temp%\_.vbs "%~1" "%~2">%tmp%
if exist %tmp% move /Y %tmp% "%%~dpnxa">nul
)
)
del %temp%\_.vbs
exit /b
:MakeReplace
>%temp%\_.vbs echo with Wscript
>>%temp%\_.vbs echo set args=.arguments
>>%temp%\_.vbs echo .StdOut.Write _
>>%temp%\_.vbs echo Replace(.StdIn.ReadAll,args(0),args(1),1,-1,1)
>>%temp%\_.vbs echo end with