Solved

Bat script replacing a string

Posted on 2010-09-19
8
389 Views
Last Modified: 2012-05-10
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_Release_130_-_Build\workspace\trunk\galopBuildUtilsV2\scripts\BatchSubstitute.bat "/JarRepositor
y/hibernate/hibernate-3.3.2.GA.jar" "/JarRepository/hibernate/hibernate-3.3.2-weaved-by-jnet-log-2.2.2.jar" C:\hudson\jobs\Galop_Release_130_-_Build\workspace\trunk\Foundation\a.classpath

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_Release_130_-_Build\workspace\trunk\galopBuildUtilsV2\scripts\BatchSubstitute.bat "/JarRepositor
y/hibernate/hibernate-3.3.2.GA.jar" "/JarRepository/hibernate/hibernate-3.3.2-weaved-by-jnet-log-2.2.2.jar" sourcepath="/JarRepository/hibernate/hiber
nate-3.3.2.GA-src.zip" C:\hudson\jobs\Galop_Release_130_-_Build\workspace\trunk\Foundation\a.classpath
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.
)

Open in new window

0
Comment
Question by:Mickeys
  • 5
  • 3
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 33711408
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
0
 

Author Comment

by:Mickeys
ID: 33711429
and if I should use ant it will look like?
0
 

Author Comment

by:Mickeys
ID: 33711536
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
<?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>

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 86

Expert Comment

by:CEHJ
ID: 33711539
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33711545
Get rid of the sourcepath attribute
0
 

Author Comment

by:Mickeys
ID: 33711549
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/hibernate-3.3.2-weaved-by-jnet-log-2.2.2.jar" sourcepath="/JarRepository/hibernate/hibernate-3.3.2.GA-src.zip
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 33711556
Try using the CDATA form
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33711602
:)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unhandled exception type Exception 18 42
How to create a textarea which saves text in HTML 8 47
Powershell File Sort 8 41
OS Selection Menu 1 47
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question