[Bash] Encoding Conversion, Newline Manipulation, String Replacement of File


Convert encoding of file from Big5 to UTF-8 [4], remove DOS newline in file [2], replace string big5 with UTF-8 via sed command, and append UNIX newline to end of file. [3]

#!/bin/bash

echo "$1: big5 to utf-8"
iconv -f big5 -t utf-8 $1 > tmp.html
mv tmp.html $1

echo "$1: remove dos newline"
tr -d '\015' <$1 > tmp.html
mv tmp.html $1

echo "$1: html meta big5 to UTF-8"
sed 's/big5/UTF-8/' -i $1

echo "$1: append newline to end of file"
sed -i -e '$a\' $1

References:

[1]bash read arguments - Google search
[2]
[3]
[4][Bash] Convert Files in Directory From Big5 to UTF-8