<?xml version="1.0" encoding="utf-8" ?> <project xmlns="http://nant.sf.net/release/0.86-beta1/nant.xsd" name="Company.Portal.Domain" default="GetFile"> <call target="GetFile" /> <target name="GetFile"> <echo message="Retrieving file contents"/> <property name="file.contents" value="0" /> <loadfile file="file.txt" property="file.contents" /> <property name="file.contents" value="${string::trim(file.contents)}" /> <echo message="contents of file is ${file.contents}"/> </target> </project>
Of course, you can skip lines 6, 9, and 10 if you want. [Edit]
<if test="${file.contents=='someValue'}"> <echo>Some value found</echo> </if>
Get full information at this link
[EDIT2]
Since you want to get the value of the third line of a text file, do this
<?xml version="1.0"?> <project name="Read3rdLine" default="main"> <property name="myInt" value="0"/> <property name="x" value="0"/> <property name="LineToRead" value="3"/> <target name="main" description="compiles the source code"> <property name="i" value="0"/> <foreach item="Line" in="file.txt" property="x" trim="Both"> <property name="i" value="${int::parse(i) + 1}"/> <if test="${i==LineToRead}"> <property name="myInt" value="${x}"/> </if> </foreach> <echo>found ${myInt} at line ${LineToRead}</echo> </target> </project>
source share