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 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.


See More: Windows equivalent to Linux sed / replace

Report •

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

Report •

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="" />
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 •

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:""=""!
>> newfile echo.!S!

Helping others achieve escape felicity


Report •

Related Solutions

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

Report •

Ask Question