>oh you are looking to do something like :  
>cat log.txt | grep "a string" | wc -l 
>
><loadfile srcfile="${output}" property="contains.errors">
>        <filterchain>
>              <linecontains>
>                  <contains value="${lookingFor}"/>
>            </linecontains>
>      </filterchain>
></loadfile>
><echo file="${basedir}/temp.txt" message="${contains.errors}"/>

The problem with this code snippet is that if there are no occurances of 
${lookingFor} in the file ${output}, then instead of an empty file being 
written out to ${basedir}/temp.txt, instead the literal string 
"${contains.errors}" gets written out to that file.  That's because the 
property contains.errors has not been set.

An even better approach would be to use the copy command, like so:

<copy file="${output}" tofile="${basedir}/temp.txt">
    <filterchain>
        <linecontains>
            <contains value="differ}"/>
        </linecontains>
    </filterchain>
</copy>

This way if there are no occurances of ${lookingFor} in file ${output}, then an 
empty file gets written out to ${basedir}/temp.txt
-Saladin


 
**********************************************************
* Saladin Sharif
* e-mail: [EMAIL PROTECTED]
* Visit homepage @ http://gaia.ecs.csus.edu/~sharifs
**********************************************************


----- Original Message ----
From: Prashant Reddy <[EMAIL PROTECTED]>
To: Saladin Sharif <[EMAIL PROTECTED]>; Ant Users List <[email protected]>
Sent: Tuesday, October 9, 2007 9:42:40 PM
Subject: Re: How to get the count of the number of lines in a file using ANT

On Tue, 2007-10-09 at 12:25 -0700, Saladin Sharif wrote:
> But what I am really after is being able to set a flag if the file
> contains one or more lines of text.

oh you are looking to do something like :  
cat log.txt | grep "a string" | wc -l 

<loadfile srcfile="${output}" property="contains.errors">
        <filterchain>
              <linecontains>
                  <contains value="${lookingFor}"/>
            </linecontains>
      </filterchain>
</loadfile>
<echo file="${basedir}/temp.txt" message="${contains.errors}"/>

So now you have the lines from the ${output} which contain ${lookingFor}
in a temp file temp.txt

After this, you could use the example Matt gave to find out the number
of lines in temp.txt

Hope this helps.
-- 

-Prashant

Don't upload, just share : www.dekoh.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


       
____________________________________________________________________________________
Be a better Heartthrob. Get better relationship answers from someone who knows. 
Yahoo! Answers - Check it out. 
http://answers.yahoo.com/dir/?link=list&sid=396545433

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to