Search This Blog

Showing posts with label replaceregexp. Show all posts
Showing posts with label replaceregexp. Show all posts

Thursday, May 29, 2014

Replace characters Using ANT

There is an inbuilt task given in ant library called 'replaceregexp'. This task is used to check about a specific pattern i.e. a regular expression and replace them with a different pattern in a single file or set of files.

Replace in a set of files

<replaceregexp match="test" replace="replacedTest" flags="gm" byline="false">
            <fileset dir="${sf.srcdir}" includes="*.txt" />
</replaceregexp>
The above task will look at all the files ending with extension 'txt' in the source directory given as 'sf.srcdir' in the properties file. In all those files, it tries to find the pattern 'test' and replaces with pattern 'replacedTest'