Trying to come up with a batch that will work with NT4 OS and find and replace specific lines in text files. There are about 60 of these text files that hold operational parameters in them. Up to this point on a weekly basis when they are updated on sundays at 7am, I have been just going in with notepad and changing the specific lines from N to Y to enable features and then ALT+F+S and ALT+F+X which i can get through 60 files pretty quickly manually changing specific lines to Y from N.
The problem now is that I am going on vacation in the near future and I am hoping I can leave for a coworker a batch that can automatically change the value from N to Y in all files in a specific directory where it finds the lines of
LS: N (or) $LASTSORT N
which would be changed to
LS: Y (or) $LASTSORT Y
The find instruction in the FOR loop would be best written to test all files by * wild cards for file name and file extension at a specific directory path that is not at the root of C: but in a path such as C:\Machine1\Parameters\Sorts\ in which the file name and extension are not altered, but it goes down a list in the directory to test all files for these specific lines and if they are set to N switch them to Y and then save the changes to the files by a write to file instruction.
The location might not be on the same exact lines within these config files for the machine parameter files, so its not as easy as just targeting a specific file extension file and knowing to just without checking just forcing say line 12 to be set to LS: Y for a xts file extension (or) $LASTSORT Y at line 8 in all files with mtx file extension.
So because the lines in which these parameters can be different from one operational config file to the next, each file has to be searched for the location of the line that needs to be altered and then when detected altering that line only.
I was messing around with the batches found here and saw that Foxidrive worked on this project at stack overflow.
http://stackoverflow.com/questions/23087463/batch-script-to-find-and-replace-a-string-in-text-file-within-a-minute-for-filesBut it uses a winscript that is called in a repl.bat file outside of the batch shown and I am not sure if NT4 supports that, so I am thinking that a pure native batch might be necessary like this one, but for all files to be tested and altered if specific lines are found. I also dont care about how long it takes as this other person at stack overflow wanted it to run faster for a 12MB file. My files are like 37k in size so it should run pretty quick anyways even if not efficient in how it carries it out.
@echo off &setlocal
set "search=%1"
set "replace=%2"
set "textfile=Input.txt"
set "newfile=Output.txt"
(for /f "delims=" %%i in (%textfile%) do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search%=%replace%!"
echo(!line!
endlocal
))>"%newfile%"
del %textfile%
rename %newfile% %textfile%
Lost with how to apply to all files by wild card and retain the original file name, and a batch that would work with limitations of NT4 OS which I have found in the past to not support all modern batch methods that work on NT5 and newer. I also dont have a NT4 system to test against currently while at home, but I do have an NT4 OEM Workstation CD and original COA in storage that I might be able to create a VM for to then test the batch against. And use this guide for Virtual PC 2007 that I have used in the past and am familiar with running virtual environments in which i can run on my Windows XP Pro SP2 tinker system to test against.
http://www.essjae.com/virtualization/winvpc-installing_winnt4.pdfAt some point I need to learn to use VMWare I suppose and get away from VPC 2007