Reputation: 1771
I am using filter in a filterchain, in a task which supports the filterchain element, i.e. the built-in Concat, Copy, LoadFile, LoadProperties, Move tasks.
So, for example, copy or move the file using a filterchain containing your linecontains filter.
Use the negate parameter on your linecontains filter to exclude lines containing that string.
Example: Consider the following code
<project default="test">
<target name="test">
<copy tofile="file.txt.edit" file="file.txt">
<filterchain>
<linecontains negate="true">
<contains value="[echo]"/>
</linecontains>
</filterchain>
</copy>
</target>
</project>
outputs:
$ cat file.txt
[echo] Your project1 location is: D:/Project/Project1
[echo] Your project2 location is: D:/Project/Project2
[script] my script running
[echo] Your project3 location is: D:/Project/Project3
[echo] Your project4 location is: D:/Project/Project4
$ cat file.txt.edit
[script] my script running
Expected:
$ cat file.txt.edit
Your project1 location is: D:/Project/Project1
Your project2 location is: D:/Project/Project2
[script] my script running
Your project3 location is: D:/Project/Project3
Your project4 location is: D:/Project/Project4
Here if i am using filterchain then complete line gets deleted. I want only the word like [echo], [script]...etc. should be removed.
Upvotes: 2
Views: 478
Reputation: 11090
Replace your linecontains
element with replaceregex
:
<tokenfilter>
<replaceregex pattern="\[echo\]" replace="" />
</tokenfilter>
For multiple token replacements, modify pattern="\[(echo|script)\]"
Upvotes: 2