Created
July 24, 2018 18:22
-
-
Save kaiware007/1d2f0c794def232884bc43ace1646d65 to your computer and use it in GitHub Desktop.
unicode番号のbmpファイルの名前をutf-16のファイル名に変更するシェルスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function convUTF16() { | |
n=`echo $((0x$1-0x10000))` | |
nn=$n | |
if [ $n -lt 0 ]; then | |
nn=`echo $((0x$1))` | |
fi | |
echo $nn | |
} | |
FILES=`find -maxdepth 1 -type f -not -name '*-*.bmp' -and -name '*.bmp'` | |
OUTPUT="output" | |
for FILE in ${FILES} | |
do | |
if [ ! -e $FILE ]; | |
then | |
echo "$FILEが存在しない" | |
continue | |
fi | |
FILE2=`basename $FILE .bmp` | |
HEXFILE=`convUTF16 $FILE2` | |
BINARY=`echo "obase=2;$HEXFILE" | bc` | |
BINARY=`printf "%020d" $BINARY` | |
W1B=`echo ${BINARY:0:10}` | |
W2B=`echo ${BINARY:10:10}` | |
W1B="110110$W1B" | |
W2B="110111$W2B" | |
W1=`echo "obase=16; ibase=2; $W1B" | bc` | |
W2=`echo "obase=16; ibase=2; $W2B" | bc` | |
W1=`echo ${W1,,}` | |
W2=`echo ${W2,,}` | |
echo "$FILE -> $HEXFILE -> $BINARY -> $W1B $W2B -> $W1 $W2" # ファイル名を出力 | |
cp $FILE $OUTPUT/$W1$W2.bmp | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment