thSoft
thSoft

Reputation: 22670

How to replace all lines of a file with their substring with Ant?

E.g. to trim the first n characters of the lines, so that

123
1234

becomes

3
34

?

Upvotes: 0

Views: 713

Answers (3)

FoxyBOA
FoxyBOA

Reputation: 5846

<target name="test">
        <property name="trim_count" value="2"/>
        <copy file="c:/test.txt" tofile="c:/test2.txt" overwrite="true">
                <filterchain>
                        <tokenfilter>
                        <linetokenizer/>
                        <replaceregex pattern="^.{1,${trim_count}}(.*)" replace="\1"/>
                        </tokenfilter>
                        <ignoreblank/>
                </filterchain>
        </copy>
</target>

Upvotes: 2

dborba
dborba

Reputation: 643

I don't think Ant supports this type of functionality by default. Instead you'd have to use an external utility. If you share some specifics of the OS you are using, as well as what kind of characters or pattern that you are attempting to remove we might be able to further aid you.

Upvotes: 0

Geo
Geo

Reputation: 96897

I think you need to write a java class to accomplish that.

Upvotes: 0

Related Questions