Hi Gilbert / All,
Thanks for the quick response. But I was guessing, is there any
other way to do this.
I mean is there any way to do this only using Ant; since I'm not
comfortable with RUBY?
Thanks again for the help.
>Regards,
>Maninder Singh
-----Original Message-----
From: Rebhan, Gilbert [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 11, 2007 12:02 PM
To: Ant Users List
Subject: RE: Extracting values from a line of a file
Hi,
-----Original Message-----
From: Maninder Singh (GR/EIL) [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 11, 2007 6:47 AM
To: [email protected]
Subject: Extracting values from a line of a file
/*
Hi,
I am trying to figure out a way to extract the values from a
line in a file.
To be more precise; there is a file that contains lines containing the
following fields (separated by spaces / tabs):
Name Age Contact_Number
I want to search for a particular name in this file (which I guess can
be done by using the Ant "loadproperties" task) and extract the age
corresponding to that Name from the file. Is there a way to do this?
*/
with =
bsf.jar (Bean Scripting Framework)
http://jakarta.apache.org/bsf/
jruby.jar
http://jruby.codehaus.org/
in sight for ant, i.e. in %ANT_HOME%/lib
you may use <script>, something like =
txtfile given =
Joe 22 1234567
Jack 33 3456789
Homer 44 1231231
and then =
<?xml version="1.0"?>
<project name="bla" default="main" basedir=".">
<!-- // Properties -->
<property name="scanfor" value="Homer"/>
<!-- Properties // -->
<target name="depends">
<script language="ruby">
<![CDATA[
File.read('Y:/test.txt').scan(/(#{$scanfor})\t(\d{1,3})\t(\d+)/)
{|a,b,c|
$project.setProperty "scanresult",b
}
]]>
</script>
</target>
<target name="main" depends="depends">
<echo>
age of == ${scanfor} ==> ${scanresult}
</echo>
</target>
</project>
** the second group of the regex = (\d{1,3}) means the age must contain
one digit and has the limit of max three digits. Someone might be 100
years old, not the normal case, but maybe ;-)
Regards, Gilbert
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]