# Ant User Manual

## Concat

### Description

Concatenates a file, or a series of files, to a single file or the console. The destination file will be created if it does not exist, though the the append attribute may be used to alter this behavior.

FileSets and/or FileLists are used to select which files are to be concatenated. There is no singular 'file' attribute to specify a single file to cat -- a fileset or filelist must also be used in these cases.

### Parameters

Attribute | Description | Required
destfile | The destination file for the concatenated stream. | No, the console will be used as the destination for the stream in the absence of this attribute.
append | Specifies whether or not the file specified by 'destfile' should be overwritten. Defaults to "yes". | No
encoding | Specifies the encoding for the input files, used only when concatenating files to the console. Please see http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html for a list of possible values. Defaults to the platform's default character encoding. | No

### Parameters specified as nested elements

#### fileset

FileSets are used to select files to be concatenated. Note that the order in which the files selected from a fileset are concatenated is not guaranteed. If this is an issue, use multiple filesets or consider using filelists.

#### filelist

FileLists are used to select files to be concatenated. The file ordering in the files attribute will be the same order in which the files are concatenated.

### Examples

Cat a string to a file:

      <cat tofile="README">Hello, World!</cat>

Cat a series of files to the console:

      <cat>
        <fileset dir="messages" includes="*important*" />
      </cat>

Cat a single file, appending if the destination file exists:

      <cat tofile="NOTES" append="true">
        <filelist dir="notes" files="note.txt" />
      </cat>

Cat a series of files, overwriting if the destination file exists:

      <cat tofile="${docbook.dir}/all-sections.xml">
        <filelist dir="${docbook.dir}/sections" files="introduction.xml,overview.xml" />
        <fileset dir="${docbook.dir}" includes="sections/*.xml" excludes="introduction.xml,overview.xml" />
      </cat>

Copyright © 2002 Apache Software Foundation. All Rights Reserved.