Use shell to process binary files

Source: Internet
Author: User
Tags ibase sybase sybase client perl script

A shell script that converts hexadecimal to decimal. The principle is similar. It should be a bit like this. It is in the Solaris environment. It is used to convert the Sybase interfaces file under Solaris to the SQL. ini of Sybase in windows.

[Code: 1: 8fab55483b]
#! /Bin/sh
# This is a script to convert the interfaces file of sybase server to SQL. ini
Sybase client on PC.
# Define sion/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, \ JUPITER \ pipe \ sybase \ query"
Echo "; WIN3_QUERY = WNLNMP, \ JUPITER \ pipe \ sybase \ query"
Echo "; \ n"
)>/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} \ n"
)>/Tmp/SQL
Done
# Convert to PC filesystem
Unix2dos/tmp/SQL>/tmp/SQL. ini [/code: 1: 8fab55483b]


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.