Search code examples
javareplaceanteol

Replacing CRLF with LF in Ant regex


I want to replace windows eol (CRLF) with Linux eol(LF) in Ant. I cannot find a way to use a regex that selects the Windows eol characters.

I tried a lot of different things and nothing seems to work.

<replaceregexp byline="true">
  <regexp pattern="\r\n" />
  <substitution expression="\n"/>
  <fileset dir="${basedir}/mydir" includes="**/*" />
</replaceregexp>


Solution

  • You may try the Ant's <fixcrlf> task which is specifically created for this purpose.

    <fixcrlf eol="unix" srcdir="${basedir}/mydir" includes="**/*" />
    

    This tasks has many advantages one of which is; it automatically repeats itself without using \r.