Skip to content

Instantly share code, notes, and snippets.

@ymt2
Last active October 8, 2015 03:28
Show Gist options
  • Save ymt2/3270253 to your computer and use it in GitHub Desktop.
Save ymt2/3270253 to your computer and use it in GitHub Desktop.
text encoding
# @todo オプションは連想配列で持つ
function wrapNkf() {
if [ $# -eq 2 ]; then
local TMP_FILENAME='/tmp/wrapNkf.'$$
if [ $1 = 'euc' ]; then
local NKF_OPTION='-e -Lu'
elif [ $1 = 'sjis' ]; then
local NKF_OPTION='-s -Lw'
elif [ $1 = 'utf8' ]; then
local NKF_OPTION='-w -Lu'
else
return 1
fi
nkf $NKF_OPTION $2 >! $TMP_FILENAME
mv -f $TMP_FILENAME $2
else
return 1
fi
}
# text-encoding: to euc
function euc() {
for i in $@;
do
wrapNkf euc $i
done;
}
# text-encoding: to sjis
function sjis() {
for i in $@;
do
wrapNkf sjis $i
done;
}
# text-encoding: to utf8
function utf8() {
for i in $@;
do
wrapNkf utf8 $i
done;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment