This
Ant Task
performs a variety of simple operations on text files.
Although not yet version 1.0, Text-Rewrite is working and can be easily intergrated into your build process.
It is
Open Source; free as in freedom and free as in beer.
Version 0.75 (September 5th, 2006)
Source distribution includes binary, source and this document.
The source also depends on private libraries that I haven't yet published, but will soon.
Step 1:
Download the binary.
Step 2:
Adds a task definition to your project, like so:
<taskdef name="TextRewrite" classname="org.cmc.textrewrite.TextRewriteTask" classpath="${libs}/text-rewrite.jar" />
You can either specify the classpath in the task definition (as above), if you haven't
added it to ant's classpath in another way (for example, at invokation).
Step 3:
Invoke TextRewrite, for example:
<TextRewrite>
<fileset dir="${src-dist}">
<include name="**/*.html" />
</fileset>
<lineCount />
<searchAndReplace find="findthis" replace="replacewiththis" />
<changeCase mode="title" />
<lineCount />
<stripEmptyLines />
<lineCount />
<tail limit="20" />
<lineCount />
</TextRewrite >
Note that you can apply any number of text transformations with a single invocation of TextRewrite.
Here we a) search & replace, b) Change to Title Case, c) Strip Empty Lines and d) tail,
printing out line counts as we go.