2009-03-27 7 views

Antwort

19

Ubuntu hat recode

$ sudo apt-get install recode 
$ recode UTF-8..latin1 *.php 

Recursively dank Ted Dziuba:

$ find . -name "*.php" -exec recode UTF-8..latin1 {} \; 
+1

Recode ist ein ziemlich Standard-Linux-Programm - nicht so Standard, dass es immer standardmäßig installiert ist, aber es sollte auf verfügbar sein alle Distributionen, nicht nur Ubuntu. –

+0

Wie kann ich das rekursiv tun? – Svish

+0

Rekursiv, es ist zu finden. -name "* .php" -exec recode UTF-8..latin1 {} \; –

9

Ich denke, iconv ist Ihre Antwort ...

Formular Mann iconv:

 
    NAME 
     iconv - Convert encoding of given files from one encoding to another 

    SYNOPSIS 
     iconv -f encoding -t encoding inputfile 

    DESCRIPTION 
     The iconv program converts the encoding of characters in inputfile from one coded 
     character set to another. The result is written to standard output unless otherwise 
     specified by the --output option. 

     ..... 

So könnte man wahrscheinlich tun ein

find $my_base_dir -name "*.php" -o -name "*.html" -exec sh -c "(\ 
    iconv -t ISO88592 -f UTF8 {} -o {}.iconv ; \ 
    mv {}.iconv {} ; \ 
)" \; 

Dies wird die entsprechend benannten Dateien rekursiv finden und re-encode sie (die temporäre Datei ist notwendig, da iconv die Ausgabe abschneiden wird, bevor mit der Arbeit begonnen wird).