Search code examples
replaceantmatching

Copy the value from a property in an Ant propertyfile to another property


I need to copy the value of one property in a propertyfile to a second property, and add that to the propertyfile.

For example, if I have a property file Test.properties containing

2018=jan;feb;mar    
2019=jan;feb;mar
2020=jan;feb;mar
********************************
name=john,math,sudha

my input property is "2020" and output is "2021", after running Ant Test.properties should contain

2018=jan;feb;mar    
2019=jan;feb;mar
2020=jan;feb;mar
2021=jan;feb;mar
********************************
name=john,math,sudha

with out changing the order How could I do that?


Solution

  •                <property name="prop.file" value="test.properties" />
                   <property name="input" value="2020" />
                   <property name="output" value="2021" />
                         <replaceregexp file="${prop.file}"
                               match="${input}(=)(.*)" 
                               replace="${input}=\2${line.separator}${output}=\2"
                               flags="gi"
                               byline="true" />