Windows equivalent to Linux sed / replace

Microsoft Windows xp professional w/serv...
April 21, 2010 at 06:33:31
Specs: Linux i686
Hello guys,


I have a file like this (from amazon):
<option key="Enable SSL encryption" value="true" />
<option key="Enable response time optimisations" value="false" />
<option key="Grab keyboard" value="false" />
<option key="HTTP proxy host" value="" />

One of the lines is:
<option key="Server host" value="" />

I'd like to select this line, change the value to something like ec2-bla-bla.amazonaws.com and update the initial file.

Can this be done using simple, native, already existing Windows batch scripting ?

I tried something with a for..but because of the special characters present in the input..the output would get very different or lack most parts.


Cheers,
Mihai


See More: Windows equivalent to Linux sed / replace

Report •

#1
April 21, 2010 at 08:26:52
If we're sticking with native scripting, then I'd probably cook something up in VBScript.

Report •

#2
April 21, 2010 at 08:34:20
edlin is the only windows utility i know of to replace char.s:
@goto 10
1,#R<option key="Server host" value="" /><option key="Server host" value="ec2-bla-bla.amazonaws.com" />
e
:10
edlin file.htm < %0.bat
::------ end
other option is vbscript as Razor mentioned, which handles these characters easily, or download gnu utility sed-for-windows.
ps: that square in middle of line 2 is a ctrl-Z

Report •

#3
April 21, 2010 at 09:24:43
@echo off > newfile & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in (myfile) do (
set S=%%a
echo "!S!" | find "Server host" > nul
if not errorlevel 1 (
set S=!S:""="c2-bla-bla.amazonaws.com"!
)
>> newfile echo.!S!
)


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
April 22, 2010 at 00:30:39
Thanks guys.

Report •

Ask Question