Change character encoding to UTF-8
This is an second version of 文字コードをまとめて変換するスクリプト - Shammerism. The before article handles multiple files at one time, but this version handles only 1 file.
#!/bin/bash NKF_CHECK=`which nkf | wc | awk '{print $1}'`; if [ $NKF_CHECK -eq 1 ];then echo "Checking nkf is ok."; else echo "$0 requires nkf but nkf is not installed or path missing. Check the nkf state."; exit 1; fi if [ $# = 1 ];then CUR=`nkf --guess $1 | awk '{print $1}'` if [ $CUR = "UTF-8" -o $CUR = "ASCII" ];then echo "Encode of $1 is $CUR. Do nothing."; else echo "Change $1's encode from $CUR to UTF-8."; mv $1 $1.$CUR; iconv -f ${CUR} -t UTF-8 $1.$CUR > $1; fi else echo "Usage: $0 filename" fi