Script to edit multiple files

Solved/Closed
Freondude Posts 1 Registration date Wednesday March 11, 2009 Status Member Last seen March 12, 2009 - Mar 12, 2009 at 04:23 PM
 New2This - Oct 29, 2010 at 03:51 AM
Hello,

How do I go about writing a script that will edit multiple text files? This is to be performed on 4 different servers that are Dell 1850's running Win Server 2003. Files extensions such as *.htm, *.ini, and *.xml. Actions would be mostly find/replace text strings and adding/removing comments. Some I'm sure there is a means to accomplish this and I am hoping this is the right place to ask.

Holler if more info is needed.

Thanks in advance
Fred
Related:

6 responses

syeddilawer Posts 1 Registration date Friday July 31, 2009 Status Member Last seen August 1, 2009 5
Aug 1, 2009 at 12:11 AM
Hi Freondude,

If you are still looking for an answer, then try this:

1.Open Notepad, Copy and paste the below script :

@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
if “%*”==”" 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.
)

2. Save the file as “xyz.bat”

The above script will parses a file line by line and will replaces a desired substring.

3. Open cmd prompt >> type the following command:

c:\xyz.bat “text-to-replace” text-to-replace-with c:\FileToEdit.txt > c:\Edited_file.txt

For more info, visit https://winitpro.wordpress.com/2009/07/31/batchscript/

Hope this helps :)
5