Need Batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
krsuresbab
Posts: 6
Joined: 13 Oct 2010 02:18

Need Batch file

#1 Post by krsuresbab » 23 Nov 2010 02:38

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.

shiva
Posts: 18
Joined: 11 Jul 2011 03:53

Re: Need Batch file

#2 Post by shiva » 02 Aug 2011 05:47

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

Post Reply