Search and Replace in DOS!!!

Off topic discussion zone.

Moderators: winston, another_commander, Cody

Post Reply
User avatar
DaddyHoggy
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 8515
Joined: Tue Dec 05, 2006 9:43 pm
Location: Newbury, UK
Contact:

Search and Replace in DOS!!!

Post by DaddyHoggy »

I've got some ini files scattered around the PCs in my lab (mostly XP32, but some Vista and some Win7) that I want to search and replace a single text string of to configure one of our Simulations remotely (we have another app already written that can send the necessary data to each remote station.

Anyway, I found this DOS bat file on line (BatchSubstitute.bat):

Code: Select all

@echo off
REM -- Prepare the Command Processor --
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION

::BatchSubstitude - parses a File line by line and replaces a substring"
::syntax: BatchSubstitude.bat OldStr NewStr File
::          OldStr [in] - string to be replaced
::          NewStr [in] - string to replace with
::          File   [in] - file to be parsed
:$changed 20100115
:$source http://www.dostips.com
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
    set "line=%%B"
    if defined line (
        call set "line=echo.%%line:%~1=%~2%%"
        for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
    ) ELSE echo.
)
and this is the file I want to change (crewstation.ini):

Code: Select all

[AR]
Enable=0

[BoscombeSSEL]
Easting=584606
Heading=38
Height=130
Northing=5665201

[Cloud]
Height=2000.000000
State=1

[DetonationIndicator]
OnEntity=0
Size=2.000000
State=1
Texture=C:\SSEL-APPS\data\effects\crater.tga
TimeOut=10.000000

[Display]
Screen=0

[Effects]
Flames=1.000000
Smoke=10.000000

[Environment]
EntityCollision=1
FriendlyVulnerabilty=0
GroundClamp=1
HeightFactor=48
ModelMap=C:\SSEL-APPS\data\vehicles\RMASmodelMap.mm
SmoothMovement=1
Terrain=Nevada2006
TerrainCollision=1
TerrainFile=C:\SSEL-APPS\data\terrain\Nevada2006\nevada2006-14-220-e.ive

[Fog]
Back=6000
Blue=255
Front=1000
Green=191
Red=191
State=1

[Jakarta]
Easting=698820
Heading=142
Height=37
Northing=-687327

[Lighting]
AmbientBlue=233
AmbientGreen=233
AmbientRed=233
Azimuth=0
Elevation=60
LightBlue=255
LightGreen=255
LightRed=255

[Local]
Application=203
Associate=0
Dynamics=TrackedVehicle
Entity=100
Forces=1
Marking=T1
Platform=Challenger
Site=155
UsePosition=1
But if I type (for testing)

Code: Select all

BatchSubstitute.bat Challenger Challenger3M crewstation.ini
I get each line of the file parsed in the DOS window and "Challenger" appears to become "Challenger3M" but when I exam the actually .ini file the substitution has not occurred.

Any help, thoughts, or alternatives much appreciated.

DH
Selezen wrote:
Apparently I was having a DaddyHoggy moment.
Oolite Life is now revealed here
User avatar
Micha
Commodore
Commodore
Posts: 815
Joined: Tue Sep 02, 2008 2:01 pm
Location: London, UK
Contact:

Re: Search and Replace in DOS!!!

Post by Micha »

DaddyHoggy wrote:
But if I type (for testing)

Code: Select all

BatchSubstitute.bat Challenger Challenger3M crewstation.ini
I get each line of the file parsed in the DOS window and "Challenger" appears to become "Challenger3M" but when I exam the actually .ini file the substitution has not occurred.

Any help, thoughts, or alternatives much appreciated.

DH
Try:

Code: Select all

BatchSubstitute.bat Challenger Challenger3M crewstation.ini > newcrewstation.ini
If that works for you, then just add a 'delete old and rename new' bit to the batch file.

Alternatively, a quick search via Google seemed to indicate that there are plenty of GUI utilities around which could do the job.
The glass is twice as big as it needs to be.
Post Reply