ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Cant <>
Subject Re: Multiple
Date Thu, 03 Jul 2008 01:40:07 GMT

If I understand your problem correctly, what you are trying to do is do a
global search and replace in a file.  I don't think ant is the appropriate
tool for this; I'd suggest Perl.  Here's a command that replaces every
occurence of each pattern in a line for all lines in a file and saves the
original file 'fileIn.txt' to 'fileIn.txt.bak

perl -i.bak -ape "s/pat1/repl1/g;s/pat2/repl2/g;...;s/patN/replN/g"

You should be able to run this with the <exec> task.

Note that if a replacement results in a line that matches a pattern that you
match later, that replacement will be made which may not be what you want.

Raymond Berg (ALLETE) wrote:
> I've got a situation where I need to search deployment files for various
> server names of a variable count when moving from staging to production
> automatically. However, I can't seem to figure out how to handle a
> dynamic replace count. I was looking at the script task but found no
> syntax that seemed to help. (Also investigated path tools and the few
> string operations available)
> I'm debating whether to create a new Ant task, but I'm not comfortable
> enough with my skills yet to attempt this.
> If it helps, my script is currently passing in a single delimited string
> as follows: find1~replace#find2~replace2#...#findn~replacen
> Any ideas?
> Raymond
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

View this message in context:
Sent from the Ant - Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message