Nova linha: diferenças entre revisões

Conteúdo apagado Conteúdo adicionado
Linha 44:
 
== Utilitários para conversão ==
Em geral, é a maneira mais simples de converter um arquivo de texto entre diferentes formatos de newline; a maioria dos editores de texto modernos podem ler e escrever arquivos usando ao menos a convenção ASCII <tt>CR</tt>/<tt>LF</tt>. Infelizmente isto não vale para o editor padrão do [[Microsoft Windows|Windows]] [[Notepad|Bloco de Notas]], mas vale para o [[Wordpad]].No [[Unix]], os comandos <tt>dos2unix</tt> e <tt>unix2dos</tt> podem ser usados para converter entre o ASCII <tt>CR</tt>+<tt>LF</tt> (DOS/Windows) e o <tt>LF</tt> (Unix) newlines - embora a sintaxe deste comando possa variar.
 
No [[Unix]], os comandos <tt>dos2unix</tt> e <tt>unix2dos</tt> podem ser usados para converter entre o ASCII <tt>CR</tt>+<tt>LF</tt> (DOS/Windows) e o <tt>LF</tt> (Unix) newlines - embora a sintaxe deste comando possa variar. The <tt>[[tr (Unix)|tr]]</tt> command is available on virtually every [[Unix-like]] system and can be used to perform arbitrary replacement operations on single characters. A DOS/Windows text file can be converted to Unix format by simply removing all ASCII <tt>CR</tt> characters with
tr -d '\r' &lt; ''inputfile'' &gt; ''outputfile''
or, if the DOS/Windows text has only <tt>CR</tt>'s, by converting <tt>CR</tt>s to <tt>LF</tt>s with
tr '\r' '\n' &lt; ''inputfile'' &gt; ''outputfile''
 
In the other direction, a conversion from Unix to DOS format can be performed with [[sed]]:
sed -e 's/$/\r/' ''inputfile'' &gt; ''outputfile''
 
The Perl alternative would allow the conversion of UNIX to DOS and vice versa to be performed on other OSs and not just UNIX:
perl -p -e 's/\n/\r\n/' ''inputfile'' &gt; ''outputfile'' # UNIX to DOS
perl -p -e 's/\r\n/\n/' ''inputfile'' &gt; ''outputfile'' # DOS to UNIX
 
On [[Unix]] systems the <tt>[[File (Unix)|file]]<tt> utility provides a convenient way of identifying what type of line breaks a text file contains.
 
== Exemplos ==