AKZ
AKZ

Reputation: 876

Remove first and last line from file?

I have a file that has lines like this.

(function($, _) {

.....


})(jQuery, jQuery.ZOF);

now I want to remove the first and last line of the file and then concat this file to another file , How could it be possible with ant?

Upvotes: 1

Views: 1670

Answers (1)

M A
M A

Reputation: 72874

loadfile can be used as follows:

    <loadfile srcfile="test.xml" property="file.first.and.last.line.removed">
      <filterchain>
        <filterreader classname="org.apache.tools.ant.filters.HeadFilter">
          <param name="lines" value="-1"/>
          <param name="skip" value="1"/>
        </filterreader>
        <filterreader classname="org.apache.tools.ant.filters.TailFilter">
          <param name="lines" value="-1"/>
          <param name="skip" value="1"/>
        </filterreader>
      </filterchain>
    </loadfile>

    <echo message="${file.first.and.last.line.removed}" file="output.txt" append="true" />

First we use a HeadFilter to read everything but skipping the first line, then we "tail" the result with a TailFilter skipping the last line.

The last line appends the content to another file.

Upvotes: 2

Related Questions