Reputation: 642
Is there a way to delete all the text from a text file using ANT except the first line? Example:
First line
Second line
.....
Line n
I want to delete everything except first line. The lines can contain any text.
Upvotes: 0
Views: 118
Reputation: 7041
Use <loadfile>
with a <headfilter>
to get just the first line of a file. Then, the original file can be overwritten using the file
attribute of <echo>
.
<!-- Use headfilter to save the file's first line in a property. -->
<loadfile srcfile="${text.file}" property="first.line">
<filterchain>
<headfilter lines="1"/>
</filterchain>
</loadfile>
<!-- Overwrite the file with only the first line. -->
<echo file="${text.file}">${first.line}</echo>
First line
Second line
.....
Line n
First line
Upvotes: 2