Hello: Recently in my work, I needed to change all the ‘\n’ to ‘\nSomeWords’. I wrote the build file as following: <project name="xxx-test" basedir="." default="test1"> <target name="test1"> <copy file="originalForReplaced.txt" tofile="forReplaced.txt" overwrite="true"> </copy> <replace file="forReplaced.txt" value=" SomeWords" > <replacetoken> </replacetoken> </replace> </target> </project> originalForReplaced.txt hello world note:between the hello and world is '\n' not '\r\n' But failed. I looked into the source code, discovered that the string to be replaced and to be replaced with have all been processed so that ‘\n’ are replaced with ‘\r\n’. but the string contains the whole text is not processed. So if the lines of the text are terminated with ‘\n’, all the line breaks will not be replaced. Then I added the code of: newString = stringReplace(newString, "\r\n","\n", false); newString = stringReplace(newString, "\n", StringUtils.LINE_SEP, false); in org.apache.tools.ant.taskdefs.Replace.processFile the problem is resolved.
Created attachment 17061 [details] test case(build file, two needed files), patch
*** This bug has been marked as a duplicate of bug 22661 ***