I've posted to 2 forums already (CodeRanch and nabble) and no one has responded with an answer .... so stack overflow ... you are my last hope. All I'm trying to do is delete the "\n" from a file using an Ant task. There simply is a bunch of empty lines in a file and I don't want them there anymore ... here is the code I used ..
<replaceregexp file="${outputFile}"
match="^[ \t\n]+$"
replace=""
byline="true"/>
It's not picking up the regular expression and I've tried a hundred different ways and I can't figure it out. Any ideas?
You may use a FilterChain (specifically an IgnoreBlank TokenFilter) to do precisely what you need:
<copy file="${input.file}" toFile="${output.file}">
<filterchain>
<ignoreblank/>
</filterchain>
</copy>
ignoreblank
will also remove lines consisting entirely of white space, but looking at your regular expression it seems that is what you want.
This works:
<replaceregexp file="..."
match="(\r?\n)\s*\r?\n"
flags="g"
replace="\1" />
The point is to match line ends manually and globally (flags="g"
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With