anttask ReplaceRegExp and empty lines

O

ogmios01

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
 
K

Kent Paul Dolan

ogmios01 said:
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>


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.
 
J

Jeff Higgins

Ogmios said:
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+
 
J

Jeff Higgins

Jeff said:
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+

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
 
J

Jeff Higgins

Jeff said:
Jeff said:
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+

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

also maybe see:
http://ant-contrib.sourceforge.net/tasks/tasks/shellscript.html
 
J

Jeff Higgins

Jeff said:
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+

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
 
J

Jeff Higgins

Ogmios said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top