Mickeys
asked on
Bat script replacing a string
Hi,
I got the script below. I am trying to replace a line with a new one.
If I do like this it works:
C:\hudson\jobs\Galop_Relea se_130_-_B uild\works pace\trunk \galopBuil dUtilsV2\s cripts\Bat chSubstitu te.bat "/JarRepositor
y/hibernate/hibernate-3.3. 2.GA.jar" "/JarRepository/hibernate/ hibernate- 3.3.2-weav ed-by-jnet -log-2.2.2 .jar" C:\hudson\jobs\Galop_Relea se_130_-_B uild\works pace\trunk \Foundatio n\a.classp ath
If I do like this it dont work. how can I write the second string to make it work? I need to have it as I trying to do.
I understand that it is this last part sourcepath="/JarRepository /hibernate /hiber
nate-3.3.2.GA-src.zip" that it think it is a file. But how can I write the string to make dos understand it is a string?
C:\hudson\jobs\Galop_Relea se_130_-_B uild\works pace\trunk \galopBuil dUtilsV2\s cripts\Bat chSubstitu te.bat "/JarRepositor
y/hibernate/hibernate-3.3. 2.GA.jar" "/JarRepository/hibernate/ hibernate- 3.3.2-weav ed-by-jnet -log-2.2.2 .jar" sourcepath="/JarRepository /hibernate /hiber
nate-3.3.2.GA-src.zip" C:\hudson\jobs\Galop_Relea se_130_-_B uild\works pace\trunk \Foundatio n\a.classp ath
The system cannot find the file specified.
I got the script below. I am trying to replace a line with a new one.
If I do like this it works:
C:\hudson\jobs\Galop_Relea
y/hibernate/hibernate-3.3.
If I do like this it dont work. how can I write the second string to make it work? I need to have it as I trying to do.
I understand that it is this last part sourcepath="/JarRepository
nate-3.3.2.GA-src.zip" that it think it is a file. But how can I write the string to make dos understand it is a string?
C:\hudson\jobs\Galop_Relea
y/hibernate/hibernate-3.3.
nate-3.3.2.GA-src.zip" C:\hudson\jobs\Galop_Relea
The system cannot find the file specified.
@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 20100915
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
) ELSE echo.
)
Even if it's possible to do it in a batch file, i suggest you don't. Use an Ant replace task or write another Java app to do it
ASKER
and if I should use ant it will look like?
ASKER
C:\temp>ant
Buildfile: build.xml
replaceText:
BUILD FAILED
C:\temp\build.xml:6: replace doesn't support the "sourcepath" attribute
Total time: 0 seconds
Buildfile: build.xml
replaceText:
BUILD FAILED
C:\temp\build.xml:6: replace doesn't support the "sourcepath" attribute
Total time: 0 seconds
<?xml version="1.0" encoding="UTF-8"?>
<project default="replaceText" basedir="./tem">
<target name="replaceText">
<replace file=".classpath" token="/JarRepository/hibernate/hibernate-3.3.2.GA.jar" value="/JarRepository/hibernate/hibernate-3.3.2-weaved-by-jnet-log-2.2.2.jar" sourcepath="/JarRepository/hibernate/hibernate-3.3.2.GA-src.zip"/>
</target>
</project>
I can't say exactly as i don't understand the batch file - at that level it becomes a 'write-only' language ;)
If you want to script Windows, Powershell is much better
http://ant.apache.org/manual/Tasks/replace.html
If you want to script Windows, Powershell is much better
http://ant.apache.org/manual/Tasks/replace.html
Get rid of the sourcepath attribute
ASKER
but that is what the string includes. It is the same error as when I used bat. I need this line into the file
/JarRepository/hibernate/h ibernate-3 .3.2-weave d-by-jnet- log-2.2.2. jar" sourcepath="/JarRepository /hibernate /hibernate -3.3.2.GA- src.zip
/JarRepository/hibernate/h
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:)