Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extracting value from a file using ant

Tags:

regex

ant

The following lines are present in the file. I would like to extract multiple data from this file.

Number of current user build lists: 23

  • 'RevisionBuild' Run time (in minutes) = 8.40

[Build] RC = 0

I used the following regex to retrieve the value 23 from this file

<ac:for param="line" list="${logFileContent}" delimiter="${line.separator}">
  <sequential>                          
<propertyregex property="noOfBuildlists"
         input="@{line}"
     regexp="(.*)Number of current user build lists: (.*)$"
     select="\2"/>  
  </sequential>
</ac:for>

But the same regex does not fetch any value when i try to fetch the other lines such as regexp="(.)[revBuild] RC = (.)$" or regexp="(.)'RevisionBuild' Run time (in minutes) = (.)$" where the extracted values should be 0 and 8.40 respectively.

Can someone please help? Thanks, Aarthi

like image 381
user1384205 Avatar asked Jul 30 '12 09:07

user1384205


1 Answers

I think this is what you are interested in. On an input file like below

Number of current user build lists: 23
'RevisionBuild' Run time (in minutes) = 8.40
[Build] RC = 0

when I execute below target

<project name="BuildModule" basedir="." default="extract.nums">
    <taskdef resource="net/sf/antcontrib/antlib.xml" />
    <property environment="env" />
    <loadfile property="file" srcfile="${basedir}/inputLog.log"/>
    <target name="extract.nums">
        <for param="line" delimiter="${line.separator}" list="${file}">
            <sequential>
                <propertyregex property="noOfBuildlists" input="@{line}" regexp="Number of current user build lists:\s*([0-9]+)$" select="\1" />
                <propertyregex property="revisionBuild" input="@{line}" regexp="'RevisionBuild' Run time\s*\(in minutes\)\s*=\s*([0-9\.]+)$" select="\1" />
                <propertyregex property="rcBuild" input="@{line}" regexp="\[Build\] RC\s*\=\s*([0-9]+)$" select="\1" />
            </sequential>
        </for>
        <echo message="Current user build : ${noOfBuildlists}" />
        <echo message="Revision Build : ${revisionBuild}" />
        <echo message="RC Build : ${rcBuild}" />
    </target>
</project>

I get below output.

[echo] Current user build : 23
[echo] Revision Build : 8.40
[echo] RC Build : 0
like image 174
Vaman Kulkarni Avatar answered Nov 15 '22 13:11

Vaman Kulkarni