Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

anttask ReplaceRegExp and empty lines

Thread view: 
ogmios01@gmail.com - 17 Mar 2006 23:10 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.

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>


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.