Script to edit multiple files

Solved/Closed
Freondude Posts 1 Registration date Wednesday 11 March 2009 Status Member Last seen 12 March 2009 - 12 Mar 2009 à 16:23
 New2This - 29 Oct 2010 à 03:51
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 31 July 2009 Status Member Last seen 1 August 2009 5
1 Aug 2009 à 00:11
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 :)