You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by momo momo <mo...@hotmail.com> on 2004/01/06 11:26:22 UTC
Replacing but not thwhole file
Hi all,
I want to replace in a file "#project" by "project" but not in the whole
file. Only from the begining to the string "# end part1". Is that possible
to do it with the task replace or replaceregexp?
I want to make exmaple2.txt from example.txt, part2 stay the same.
example.txt:
#begin part1
#project.key1=1
#project.key2=A
#end part1
#begin part2
#project.key3=Z
project.key3=W
#end part2
example2.txt:
#begin part1
project.key1=1
project.key2=A
#end part1
#begin part2
#project.key3=Z
project.key3=W
#end part2
I tried some codes:
<replaceregexp file="example.txt"
match="#(project.*# end : config liée à l'environnement.*)"
replace="\1"
flags="gs"
/>
but I didn't succeed!
I allways get all changes or one change...
Does anyone have an idea?
Thanks to help me
_________________________________________________________________
Trouvez l'âme soeur sur MSN Rencontres http://g.msn.fr/FR1000/9551
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
RE: Replacing but not thwhole file
Posted by didge <di...@foundrylogic.com>.
You can't turn replacement on and off within a file, but you can try to use
token replacement for the comment character itself. For example,
example.txt:
#begin part1
@PART1@project.key1=1
@PART1@project.key2=A
#end part1
#begin part2
@PART2@project.key3=Z
project.key3=W
#end part2
Now, you can set the tokens PART1 and PART2 separately to either "" (empty
string) or "#". If you always want a particular key set, then don't prefix
it with a token, e.g. project.key3. For example:
<copy file="example.txt" toFile="example2.txt">
<filterset>
<filter token="PART1" value=""/>
<filter token="PART2" value="#"/>
</filterset>
</copy>
Another alternative would be to use a smarter preprocessor, such as VPP,
http://vpp.sourceforge.net.
didge
> -----Original Message-----
> From: momo momo [mailto:molbiatch@hotmail.com]
> Sent: Tuesday, January 06, 2004 2:26 AM
> To: user@ant.apache.org
> Subject: Replacing but not thwhole file
>
>
> Hi all,
>
> I want to replace in a file "#project" by "project" but not in the whole
> file. Only from the begining to the string "# end part1". Is that
> possible
> to do it with the task replace or replaceregexp?
>
> I want to make exmaple2.txt from example.txt, part2 stay the same.
> example.txt:
> #begin part1
> #project.key1=1
> #project.key2=A
> #end part1
>
> #begin part2
> #project.key3=Z
> project.key3=W
> #end part2
>
>
> example2.txt:
> #begin part1
> project.key1=1
> project.key2=A
> #end part1
>
> #begin part2
> #project.key3=Z
> project.key3=W
> #end part2
>
> I tried some codes:
> <replaceregexp file="example.txt"
> match="#(project.*# end : config liée à l'environnement.*)"
> replace="\1"
> flags="gs"
> />
>
> but I didn't succeed!
> I allways get all changes or one change...
>
> Does anyone have an idea?
> Thanks to help me
>
> _________________________________________________________________
> Trouvez l'âme soeur sur MSN Rencontres http://g.msn.fr/FR1000/9551
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org