[20190930]oracle raw类型转化number脚本.txt
[20190930]oracle raw类型转化number脚本.txt
--//写一个简单oracle raw转化number脚本,简单说明:
--//输入必须是c1,02 或者 c102,不支持c1,2格式。
--//raw2num.sh 脚本放在最后.
--//测试:
$ cat otest.txt | xargs -n 1 -I {} bash -c "./raw2num.sh {};echo {} " | paste - -
0 80
1 c1,02
2 c1,03
25 c1,1a
123 c2,02,18
4100 c2,2a
-4100 3d,3c,66
41000000 c4,2a
-41000000 3b,3c,66
132004078 c5,02,21,01,29,4f
2.01 c1,03,02
.3 c0,1f
.00000125 be,02,1a
115.200003 c2,02,10,15,01,04
-.00000125 41,64,4c,66
-.3 3f,47,66
-1 3e,64,66
-5 3e,60,66
-20032 3c,63,65,45,66
-234.432 3d,63,43,3a,51,66
999999999999999999999999999999999999999900000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ff,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64
-999999999999999999999999999999999999990000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02
.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 80,02
-.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 7f,64,66
123456789012345678901234567890123456789000 d5,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b
-123456789012345678901234567890123456780000 2a,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b
.123456789012345678901234567890123456789 c0,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b
-.12345678901234567890123456789012345678 3f,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b
$ cat otest.txt
80
c1,02
c1,03
c1,1a
c2,02,18
c2,2a
3d,3c,66
c4,2a
3b,3c,66
c5,02,21,01,29,4f
c1,03,02
c0,1f
be,02,1a
c2,02,10,15,01,04
41,64,4c,66
3f,47,66
3e,64,66
3e,60,66
3c,63,65,45,66
3d,63,43,3a,51,66
ff,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64
00,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02,02
80,02
7f,64,66
d5,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b
2a,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b
c0,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b,0d,23,39,4f,5b
3f,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b,59,43,2d,17,0b
$ cat raw2num.sh
#! /bin/bash
#! oracle raw convert number
odebug=${ODEBUG:-0}
# process input parameter ,delete 0x and "," and all spaces. save to variable v_raw. and its length to variable v_len.
v_raw="$*"
v_raw=${v_raw//0x/}
v_raw=${v_raw//[, ]/}
v_len=${#v_raw}
v_tmp=$(( $v_len % 2 ))
if [ $v_tmp -ne 0 -o $v_len -gt 42 ]; then
echo "$v_raw is illegal! v_len=$v_len or length of v_len>42"
exit 2
fi
if [ $odebug -eq 1 ] ; then
echo v_ram="$v_raw"
fi
if [ "$v_raw" == "80" ]; then
result=0
echo "$result"
exit 0
elif [ "$v_raw" \> "80" ]; then
v_res="0."
v_exp=$(printf "%2d" $(( "0x"${v_raw:0:2} - 0xc0 )))
if [ $odebug -eq 1 ] ; then
echo v_ram="$v_raw" v_exp="$v_exp" v_len="$v_len"
fi
for ((i=2;i<$v_len;i+=2))
do
v_tmp=$(printf "%02d" $(( "0x"${v_raw:i:2} -0x1 )))
if [ $v_tmp -lt 0 -o $v_tmp -gt 99 ]; then
echo "$v_raw is illegal! offset $i = 0x${v_raw:i:2}"
exit 3
fi
if [ $v_tmp -eq 0 -a $i -eq $(( $v_len - 2 )) ];then
echo "$v_raw is illegal! offset $i = 0x${v_raw:i:2}"
exit 3
fi
v_res=${v_res}${v_tmp}
done
#result=$(echo "scale=132; 100^${v_exp} * ${v_res} " | bc -l | tr -d '\n\\\r' | sed -e "s/\.\([0-9]*[1-9]\)0\+$/.\1/" -e "s/\.0\+$//")
else
#negative
v_res="-0."
v_exp=$(printf "%2d" $(( 0xff - "0x"${v_raw:0:2} -0xc0 )))
## substr last 2 char, normal is 0x66 (102)
v_len=$(( $v_len - 2 ))
v_last=$(printf "%02d" $(( "0x"${v_raw:v_len:2} )))
if [ $odebug -eq 1 ] ; then
echo v_ram="$v_raw" v_exp="$v_exp" v_len-2="$v_len" v_last="$v_last"
fi
if [ "$v_last" != "102" -a $v_len -lt 40 ]; then
echo "$v_raw is illegal! offset $v_len = 0x${v_raw:v_len:2}"
exit 4
fi
for ((i=2;i<$v_len;i+=2))
do
v_tmp=$(printf "%02d" $(( 0x65 - "0x"${v_raw:i:2} )))
if [ $v_tmp -lt 0 -o $v_tmp -gt 99 ]; then
echo "$v_raw is illegal! offset $i = 0x${v_raw:i:2}"
exit 3
fi
if [ $v_tmp -eq 0 -a $i -eq $(( $v_len - 2 )) ];then
echo "$v_raw is illegal! offset $i = 0x${v_raw:i:2}"
exit 3
fi
v_res=${v_res}${v_tmp}
done
if [ $v_len -eq 42 -a "$v_last" != '102' ]; then
v_tmp=$(printf "%02d" $(( 101 - $v_last )))
if [ $v_tmp -le 0 -o $v_tmp -gt 99 ]; then
echo "$v_raw is illegal! offset $v_len = 0x${v_raw:v_len:2}"
exit 3
fi
v_res=${v_res}${v_last}
fi
#result=$(echo "scale=132; 100^${v_exp} * ${v_res} " | bc -l | tr -d '\n\\\r' | sed -e "s/\.\([0-9]*[1-9]\)0\+$/.\1/" -e "s/\.0\+$//")
fi
if [ $odebug -eq 1 ] ; then
echo v_ram="$v_raw" v_exp="$v_exp" v_len="$v_len" v_res="$v_res"
fi
result=$(echo "scale=132; 100^${v_exp} * ${v_res} " | bc -l | tr -d '\n\\\r' | sed -e "s/\.\([0-9]*[1-9]\)0\+$/.\1/" -e "s/\.0\+$//")
echo "$result"
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库