Dennis Williamson と Alberto Zaccagni の回答を使用して、すべてのサブディレクトリから指定されたファイル タイプのすべてのファイルを変換する次のスクリプトを思いつきました。出力は、次のように指定された 1 つのフォルダーに収集されます。/path/to/destination
mkdir /path/to/destination
for a in $(find . -name "*.php");
do
filename=$(basename $a);
echo $filename
iconv -f iso-8859-1 -t utf-8 <"$a" >"/path/to/destination/$filename";
done
関数 basename は、ファイルのパスなしでファイル名を返します。
代替 (ユーザー インタラクティブ):
古いファイルを上書きするか、単に名前を変更するかを決定できるユーザー インタラクティブ スクリプトも作成しました。追加の感謝はtbsallingに行きます
for a in $(find . -name "*.tex");
do
iconv -f iso-8859-1 -t utf-8 <"$a" >"$a".utf8 ;
done
echo "Should the original files be replaced (Y/N)?"
read replace
if [ "$replace" == "Y" ]; then
echo "Original files have been replaced."
for a in $(find . -name "*.tex.utf8");
do
file_no_suffix=$(basename -s .tex.utf8 "$a");
directory=$(dirname "$a");
mv "$a" "$directory"/"$file_no_suffix".tex;
done
else
echo "Original files have been converted and converted files were saved with suffix '.utf8'"
fi
これを楽しんでください。それを改善するためのコメントに感謝します。ありがとう!