起因:
shell脚本——将每行的文字自动插入到数据库中
File=$1
if [[ "$File" == "" ]]; then
echo "usage: $0 File"
exit -1
fi
while read line
do
if [ -z "$line" ];then
echo "is null"
else
echo ${line%?}
mysql $database -hIp -uUsername -pPassword -e "insert into tablename (ColumnName) values('${line}');"
fi
done < ${File}
插入到数据库之中数据显示异常
原因是:
文本中每行行尾有一个换行符
shell中去掉最后一个字符
${line%?}
脚本修改为
mysql $database -hIp -uUsername -pPassword -e "insert into tablename (ColumnName) values('${line%?}');"
删除错误数据,重新运行脚本即可