tags:

views:

233

answers:

3

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

123
1234

becomes

3
34

?

A: 

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

Geo
A: 

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.

dborba
+2  A: 
<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>
FoxyBOA
Hmm, I thought of replaceregexp (not replaceregex!) but couldn't come up with a solution because I was thinking along the lines of specifying the substring length with a number. This solution doesn't scale well with the length of the trimmed substring, but it is simple, and anyway, this length will be 6 in my case. Thanks!
thSoft
Welcome. I updated my original post to do it more scalable.
FoxyBOA
Thanks, great! I had to remove the <stringtokenizer/> filter, though, or replace it with <linetokenizer/>.
thSoft
Yes, you are correct. I think that <linetokenizer/> is more appropriate solution.
FoxyBOA