This is an example showing how to concatenates files using Ant script.
1. Assume you have the following files in your Ant project folder.
ant-for-example | - build.xml | - Text-1.txt | - Text-2.txt | - Text-3.txt
2. Each of the .txt files has similar content as follow. Pay attention to the newline characters at the end.
This is Test-1.txt <EOF>
3. Here is the build.xml.
<project name="ant-concat-example" default="run" basedir=".">
<target name="run">
<concat destfile="${basedir}/Full.txt">
<sort>
<fileset dir="${basedir}">
<include name="Test-*.txt"/>
</fileset>
</sort>
</concat>
</target>
</project>
4. Run the Ant script you will get the Full.txt as below.
This is Test-1.txt This is Test-2.txt This is Test-3.txt <EOF>
5. See the newline characters in the result text file above. To insert a newline for every included file, you can add the fixlastline attribute.
<project name="ant-concat-example" default="run" basedir=".">
<target name="run">
<concat destfile="${basedir}/Full.txt" fixlastline="true">
<sort>
<fileset dir="${basedir}">
<include name="Test-*.txt"/>
</fileset>
</sort>
</concat>
</target>
</project>
Done =)
Reference:
