Page 1 of 1

Need Batch file

Posted: 23 Nov 2010 02:38
by krsuresbab
I need batch file i have 1 notepad file in my system(Local) i need to find and replace some lines.


Folder Structure:

C:\svn_working_folder\autoconfigsites\www.alwanad.com\parsermatic(this is notepad file)

C:\svn_working_folder\autoconfigsites\forum.cancerkids.org\parsermatic(this is notepad file)

Find this lines:

core.http.userAgent=BoardPulse
core.http.userAgentURL=http://www.boardpulse.com; compatible; MSIE 6.0
core.http.fromEmail=pfbcrawler@intelliseek.com

Replace this lines:

core.http.userAgent=BlogPulse
core.http.userAgentURL=http://www.Blogpulse.com; compatible; MSIE 6.0
core.http.fromEmail=suppoert@blogpulse.com

I need to replace this file each and every project.


Pls help.

Re: Need Batch file

Posted: 02 Aug 2011 05:47
by shiva
hi,
here is the solution to your problem,
BatchSubstitute.bat "core.http.userAgent=BoardPulse" "core.http.userAgent=BlogPulse" a.txt
BatchSubstitute.bat "text_to_be_replaced" "new_text" name_of_the_file

the file BatchSubstitute.bat is as follows:

FILE name :BatchSubstitute.bat

@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 >>j.txt
) ELSE echo.
)

del a.txt

pause

rename j.txt a.txt

thank you
shiva shankar