# !/bin/bash
#a=",aaa,bbb,ccc,ddd,eee"
OLD_IFS="$IFS"
IFS=","
OUTFILE=outfile.csv
INPUTFILE=inputfile.csv
declare -i i=0
declare -i k
declare -i result
echo -n ""> $OUTFILE
echo -n ""> $OUTFILE
a=`head -1 $INPUTFILE | tr -d "\r"`
brr=($a)
for s in ${brr[@]}
do
i=i+1
done
for((n=1;n<i;n++))
do
echo -n ",${brr[$n]}">>$OUTFILE
done
echo "" >>$OUTFILE
var=`echo "ibase=10;obase=16;2^($i-1)"|bc`
for((j=0x1;j<0x$var;j=j+0x1))
do
for((k=0;k<$i-1;k++))
do
result=`echo "ibase=10;obase=16;2^$k"|bc`
let "result=0x$result&$j"
if [ $result -ne 0 ];then
echo -n "${brr[$k+1]}_">>$OUTFILE
fi
done
echo -n "on_other_off,">>$OUTFILE
for((k=0;k<$i-1;k++))
do
result=`echo "ibase=10;obase=16;2^$k"|bc`
let "result=0x$result&j"
if [ $result -ne 0 ];then
echo -n "1,">>$OUTFILE
else
echo -n "0,">>$OUTFILE
fi
done
echo "">>$OUTFILE
done
IFS="$OLD_IFS"
#a=",aaa,bbb,ccc,ddd,eee"
OLD_IFS="$IFS"
IFS=","
OUTFILE=outfile.csv
INPUTFILE=inputfile.csv
declare -i i=0
declare -i k
declare -i result
echo -n ""> $OUTFILE
echo -n ""> $OUTFILE
a=`head -1 $INPUTFILE | tr -d "\r"`
brr=($a)
for s in ${brr[@]}
do
i=i+1
done
for((n=1;n<i;n++))
do
echo -n ",${brr[$n]}">>$OUTFILE
done
echo "" >>$OUTFILE
var=`echo "ibase=10;obase=16;2^($i-1)"|bc`
for((j=0x1;j<0x$var;j=j+0x1))
do
for((k=0;k<$i-1;k++))
do
result=`echo "ibase=10;obase=16;2^$k"|bc`
let "result=0x$result&$j"
if [ $result -ne 0 ];then
echo -n "${brr[$k+1]}_">>$OUTFILE
fi
done
echo -n "on_other_off,">>$OUTFILE
for((k=0;k<$i-1;k++))
do
result=`echo "ibase=10;obase=16;2^$k"|bc`
let "result=0x$result&j"
if [ $result -ne 0 ];then
echo -n "1,">>$OUTFILE
else
echo -n "0,">>$OUTFILE
fi
done
echo "">>$OUTFILE
done
IFS="$OLD_IFS"
【说明】
1、首先将原始excel表保存成.csv格式,名字为inputfile.csv,见文件夹中inputfile.csv
2、在linux下执行脚本sh script.sh
3、等待生成outfile.csv文件,将其保存为.xls格式即可
1、首先将原始excel表保存成.csv格式,名字为inputfile.csv,见文件夹中inputfile.csv
2、在linux下执行脚本sh script.sh
3、等待生成outfile.csv文件,将其保存为.xls格式即可