<p>Vous pouvez utiliser <code>tr</code> to convert from DOS to Unix; cependant, vous pouvez only do this safely if CR appears in your file only as the first byte of a CRLF byte pair. This is usually the case. You then use:</p>
<pre><code class="lang-auto">tr -d '\015' <DOS-file >UNIX-file
</code></pre>
<p>Notez que the name <code>DOS-file</code> is different from the name <code>UNIX-file</code>; if you try to use the same name twice, you will end up with no data in the file.</p>
<p>Vous pouvez’t do it the other way round (with standard ‘tr’).</p>
<p>If you know how to enter carriage return into a script (control-V, control-M to enter control-M), then:</p>
<pre><code class="lang-auto">sed 's/M$//' # DOS to Unix
sed 's/$/M/' # Unix to DOS
</code></pre>
<p>where the ‘M’ is the control-M character. Vous pouvez également use the <code>bash</code> <a href="http://www.gnu.org/software/bash/manual/bash.html#ANSI_002dC-Quoting">ANSI-C Quoting</a> mechanism to specify the carriage return:</p>
<pre><code class="lang-auto">sed $'s/\r$//' # DOS to Unix
sed $'s/$/\r/' # Unix to DOS
</code></pre>
<p>Cependant, if you’re going to have to do this very often (more than once, roughly speaking), it is far more sensible to install the conversion programs (e.g. <a href="http://linux.die.net/man/1/dos2unix"><code>dos2unix</code></a> and <a href="http://linux.die.net/man/1/unix2dos"><code>unix2dos</code></a>, or perhaps <a href="http://www.delorie.com/djgpp/doc/utils/utils_4.html"><code>dtou</code></a> and <a href="http://www.delorie.com/djgpp/doc/utils/utils_5.html"><code>utod</code></a>) and use them.</p>
<p>If vous devez process entire directories and subdirectories, vous pouvez utiliser <code>zip</code>:</p>
<pre><code class="lang-auto">zip -r -ll zipfile.zip somedir/
unzip zipfile.zip
</code></pre>
<p>This will create a zip archive with line endings changed from CRLF to CR. <code>unzip</code> will then put the converted files back in place (and ask you file by file - vous pouvez answer: Yes-to-all). Credits to <span class="mention">@vmsnomad</span> for pointing this out.</p>