用shell处理二进制文件

我以前写过一个shell script,其中有一部分是转换十六进制到十进制。道理差不多,应该和这个有点象,是Solaris环境下的。 用来转换 Solaris下的Sybase interfaces file windows环境下的Sybasesql.ini

[code:1:8fab55483b]

#!/bin/sh

# This is a script to convert the interfaces file of sybase server to sql.ini of

sybase client on PC.

# Illusion/ICIL

# Intialize sql.ini

(

echo ";; Sybase Interfaces file"

echo ";;"

echo ";; [<database_server_name>]"

echo ";; <link_type>=<network_driver>,<connection_info>"

echo ";;"

echo ";; Examples:"

echo ";; [JUPITER]"

echo ";; QUERY=NLMSNMP,/JUPITERpipesybasequery"

echo ";; WIN3_QUERY=WNLNMP,/JUPITERpipesybasequery"

echo ";; "

)>/tmp/sql

# May ignore the backup server for sybase

servers=`grep -i '^[a-z]' /opt/sybase11/interfaces | sed '/_BACKUP/d'`

for server in ${servers}; do

echo "Converting ${server} info ..."

server_info=`grep -A 2 ^"${server}"$ /opt/sybase11/interfaces`

master_info=`echo "${server_info}" | grep "master" | awk '{ print $5 }'`

# May use a perl script to convert the number of IP too.

master_ip1=`echo "${master_info}" | cut -c11-12`

master_ip1=`echo "${master_ip1}" | tr '[a-z]' '[A-Z]'`

master_ip1=`echo "obase=10; ibase=16; ${master_ip1}" | bc`

master_ip2=`echo "${master_info}" | cut -c13-14`

master_ip2=`echo "${master_ip2}" | tr '[a-z]' '[A-Z]'`

master_ip2=`echo "obase=10; ibase=16; ${master_ip2}" | bc`

master_ip3=`echo "${master_info}" | cut -c15-16`

master_ip3=`echo "${master_ip3}" | tr '[a-z]' '[A-Z]'`

master_ip3=`echo "obase=10; ibase=16; ${master_ip3}" | bc`

master_ip4=`echo "${master_info}" | cut -c17-18`

master_ip4=`echo "${master_ip4}" | tr '[a-z]' '[A-Z]'`

master_ip4=`echo "obase=10; ibase=16; ${master_ip4}" | bc`

master_ip=`echo "${master_ip1}.${master_ip2}.${master_ip3}.${master_ip4}

`

master_port=`echo "${master_info}" | cut -c7-10`

master_port=`echo "${master_port}" | tr '[a-z]' '[A-Z]'`

master_port=`echo "obase=10; ibase=16; ${master_port}" | bc`

# add the server info to sql.ini

(

echo "[${server}]"

echo "master=NLWNSCK,${master_ip},${master_port}"

echo "query=NLWNSCK,${master_ip},${master_port} "

)>>/tmp/sql

done

# convert to PC filesystem

unix2dos /tmp/sql > /tmp/sql.ini[/code:1:8fab55483b

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值