Is it possible for the ant task ReplaceRegExp to remove empty lines
from a file... I tried the following
<project name="ReplacementTest" default="test" basedir=".">
<target name="test">
<replaceregexp match="\n\n" replace="\n" flags="g" byline="false">
<fileset file="inp.txt"/>
</replaceregexp>
</target>
</project>
But it isn't working.
Regards,
Ogmios
Roedy Green - 18 Mar 2006 00:17 GMT
> <replaceregexp match="\n\n" replace="\n" flags="g" byline="false">
Look at your files with a hex viewer. do the they have
\n\n or \r\n\r\n?

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Kent Paul Dolan - 18 Mar 2006 04:33 GMT
> Is it possible for the ant task ReplaceRegExp to remove empty lines
> from a file... I tried the following
> <project name="ReplacementTest" default="test" basedir=".">
> <target name="test">
> <replaceregexp match="\n\n" replace="\n" flags="g" byline="false">
> <fileset file="inp.txt"/>
> </replaceregexp>
> </target>
> </project>
> But it isn't working.
Check your documentation. Most regular expression parsers
work "line by line", so that matches that span lines will
fail. The Perl regular expression parsing includes a way
to parse the file as a single string, but that's exceptional.
It may well be that Ant either "won't do that", or else
"won't do that without special measures". I wouldn't know,
not yet having used Ant.
FWIW
xanthian.
Jeff Higgins - 18 Mar 2006 14:41 GMT
Ogmios wrote:
> Is it possible for the ant task ReplaceRegExp to remove empty lines
> from a file... I tried the following
[snip]
you could use
awk '/./'
to remove all blank lines from a file
but I don't know how to make an ant task to run awk
a java implementation of awk is available at
http://jawk.sourceforge.net/ but requires JDK 1.5+
Jeff Higgins - 18 Mar 2006 16:25 GMT
> Ogmios wrote:
>> Is it possible for the ant task ReplaceRegExp to remove empty lines
[quoted text clipped - 7 lines]
> a java implementation of awk is available at
> http://jawk.sourceforge.net/ but requires JDK 1.5+
maybe see:
http://ant.apache.org/faq.html#batch-shell-execute
http://ant.apache.org/faq.html#shell-redirect-2
to run awk from a task
Jeff Higgins - 18 Mar 2006 17:06 GMT
>> Ogmios wrote:
>>> Is it possible for the ant task ReplaceRegExp to remove empty lines
[quoted text clipped - 12 lines]
> http://ant.apache.org/faq.html#shell-redirect-2
> to run awk from a task
also maybe see:
http://ant-contrib.sourceforge.net/tasks/tasks/shellscript.html
Jeff Higgins - 18 Mar 2006 18:50 GMT
> Ogmios wrote:
>> Is it possible for the ant task ReplaceRegExp to remove empty lines
[quoted text clipped - 7 lines]
> a java implementation of awk is available at
> http://jawk.sourceforge.net/ but requires JDK 1.5+
an example build file
<project name="noblanks" default="noblanklines" basedir=".">
<description>
demonstrate using awk from ant
</description>
<!-- set global properties for this build -->
<property name="javadir" location="C:\Sun\AppServer\jdk\bin"/>
<target name="noblanklines">
<exec dir="${javadir}" executable="java.exe" os="Windows XP"
output="testout.txt">
<arg value="-jar"/>
<arg value="c:\libraries\java\jawk\jawk.0_11.jar"/>
<arg value="/./"/>
<arg value="c:\test\test.txt"/>
</exec>
</target>
</project>
for test.txt equals
This is line 1.
This is line 2.
This is line 3.
This is line 4.
produces testout.txt equals
This is line 1.
This is line 2.
This is line 3.
This is line 4.
on my machine
Jeff Higgins - 19 Mar 2006 20:15 GMT
Ogmios wrote:
> Is it possible for the ant task ReplaceRegExp to remove empty lines
> from a file... I tried the following
[snip]
Yet another solution.
Thanks to Jan Materne
http://java2.5341.com/msg/52862.html
<project name="noblanks" default="noblanklines" basedir=".">
<target name="noblanklines">
<concat destfile="testout.txt">
<fileset dir= "." includes="testin.txt "/>
<filterchain>
<tokenfilter><ignoreblank/></tokenfilter>
</filterchain>
</concat>
</target>
</project>