Sponsored Content
Top Forums Shell Programming and Scripting Converting hex to ascii/decimal Post 302509622 by Shiftkey on Thursday 31st of March 2011 09:45:16 AM
Old 03-31-2011
Converting hex to ascii/decimal

I am writing a bash script to do some parsing on a log and I am running into a problem when it comes to converting only certain sections of the file from hex to ascii or hex to decimal.

Data Example:

Quote:
------------
ip = 10.2.3.4
------------
Hardware= [ 38 30 30 30 ]
Errors= [ 00 a1 ]
Full= [ 63 ]
SW Version= [ 31 2e 38 2e 31 2e 31 30 39 ]
Test= [ 76 ]
------------
ip = 10.2.3.8
------------
Hardware= [ 34 30 30 30 ]
Errors= [ 00 a1 ]
Full= [ 45 ]
SW Version= [ 31 2e 38 2e 31 2e 31 30 39 ]
Test= [ 76 ]
The hex values after Hardware and SW Version I need to convert from Hex to ASCII and the Errors, Full, Test values I need to convert from hex to decimal.

The output should look like the following:

Quote:
------------
ip = 10.2.3.4
------------
Hardware= [ 8000 ]
Errors= [ 161 ]
Full= [ 99 ]
SW Version= [ 1.8.1.109]
Test= [ 118 ]
------------
ip = 10.2.3.8
------------
Hardware= [ 4000]
Errors= [ 161 ]
Full= [ 69 ]
SW Version= [ 1.8.1.109 ]
Test= [ 118 ]
Thanks for any help!
 

10 More Discussions You Might Find Interesting

1. Programming

converting hex to ascii

Hi everyone! I was wondering if anyone knows how to change hex code back into ascii. when i process a form: " / " turn to " %2F " " @ " turns to " %40 " " ' " turns to " %27 " " ( " turns to " %28 " " ) " turns to " %29 " this is my code so far: order.txt thanks, primal p.s.... (1 Reply)
Discussion started by: primal
1 Replies

2. UNIX for Dummies Questions & Answers

Ascii To Hex

How will I display on screen a UNIX ascii file with its HEX equivalent. I want to check whether 0D 0A is coming at the end of the file which I am generating from UNIX. (1 Reply)
Discussion started by: augustinep
1 Replies

3. UNIX for Advanced & Expert Users

Converting Binary decimal coded values to Ascii Values

Hi All, Is there any command which can convert binary decimal coded values to ascii values... i have bcd values like below оооооооооооо0о-- -v - Pls suggest a way to convert this. Thanks, Deepti.Gaur (3 Replies)
Discussion started by: gaur.deepti
3 Replies

4. Shell Programming and Scripting

hex to decimal

hi all, echo "ibase=16;obase=10;11" | bc shouldn't i get 17? i am getting 11 i am trying to convert 11 (hex) to decimal stuck! JAK (4 Replies)
Discussion started by: jakSun8
4 Replies

5. Programming

After converting the hexstr to Hex and storing the Hex in a char*

Hi All, My main intension of is to convert the Hexstring stored in a char* into hex and then prefixing it with "0x" and suffix it with ',' This has to be done for all the hexstring char* is NULL. Store the result prefixed with "0x" and suffixed with ',' in another char* and pass it to... (1 Reply)
Discussion started by: rvan
1 Replies

6. Programming

ascii to hex

Hello guys, i want to convert a text file to hex and have written this code : int main(int argc, char **argv) { ifstream file; string fileName = "CODEZ"; file.open(fileName.c_str()); // oeffen im Text-Modus if(file) {... (5 Replies)
Discussion started by: Kingbruce
5 Replies

7. Shell Programming and Scripting

Decimal to hex conversion

Dear All PROs Thanks in advance need a shell for Decimal to hex conversion input file (decimal values) 65,5,48,66,133,131,118,47 65,5,48,66,133,131,83,63 . . desire output should be (Hex value)... (11 Replies)
Discussion started by: The_Archer
11 Replies

8. Shell Programming and Scripting

Convert hex to decimal

can someone help me in converting hex streams to decimal values using perl script Hex value: $my_hex_stream="0c07ac14001676"; Every hex value in the above stream should be converted in to decimal and separated by comma. The output should be: 12,07,172,20,00,22,118 (2 Replies)
Discussion started by: Arun_Linux
2 Replies

9. Shell Programming and Scripting

Converting decimal to hex

How to convert decimal value to hex and than take 1st digits as variable sample data 84844294,5,6 51291736,2,3 84844294,5,6 51291736,2,3 i can use {printf "%x,%d\n",$1,$2} but than i want to filter base on 1st hex digit 1st recrd (1 Reply)
Discussion started by: before4
1 Replies

10. Shell Programming and Scripting

Convert Hex to Ascii in a Ascii file

Hi All, I have an ascii file in which few columns are having hex values which i need to convert into ascii. Kindly suggest me what command can be used in unix shell scripting? Thanks in Advance (2 Replies)
Discussion started by: HemaV
2 Replies
termiox(7)						 Miscellaneous Information Manual						termiox(7)

NAME
termiox - extended general terminal interface SYNOPSIS
fildes, request, arg) DESCRIPTION
The extended general terminal interface supplements the termio(7) general terminal interface by adding support for asynchronous hardware flow control and local implementations of additional asynchronous features. Some systems may not support all of these capabilities because of hardware or software limitations. Other systems may not permit certain functions to be disabled. In such cases, the appropriate bits are ignored. If the capabilities can be supported, the interface described here must be used. Hardware Flow Control Modes Hardware flow control supplements the termio and character flow control (see termio(7)). Character flow control occurs when one device controls the data transfer of another device by inserting control characters in the data stream between devices. Hardware flow control occurs when one device controls the data transfer of another device by using electrical control signals on wires (circuits) of the asyn- chronous interface. Character flow control and hardware flow control can be simultaneously set. In asynchronous, full duplex applications, the use of the Electronics Industries Association's EIA-232-D Request To Send (RTS) and Clear To Send (CTS) circuits is the preferred method of hardware flow control. The EIA-232-D standard specified only unidirectional hardware flow control where the Data Circuit-terminating Equipment or Data Communica- tions Equipment (DCE) indicates to the Data Terminal Equipment (DTE) to stop transmitting data. The termiox interface allows both unidi- rectional and bidirectional hardware flow control; when bidirectional flow control is enabled, either the DCE or DTE can indicate to each other to stop transmitting data across the interface. Clock Modes Isochronous flow control and clock mode communication are not supported. Terminal Parameters Parameters that control the behavior of devices providing the termiox interface are specified by the structure, defined in the header file. Several system calls (see ioctl(5)) that fetch or change these parameters use the structure which contains the following members: The field describes hardware flow control modes: Enable RTS hardware flow control on input. Enable CTS hardware flow control on input. The RTS and CTS circuits are involved in establishing CCITT modem connections. Since RTS and CTS circuits are used both by CCITT modem connections and by hardware flow control, CCITT modem and hardware flow control cannot be simultaneously enabled. Variations of different hardware flow control methods can be selected by setting the appropriate bits. For example, bidirectional RTS/CTS flow control is selected by setting both the and bits. Unidirectional CTS hardware flow control is selected by setting only the bit. If is set, the Request to Send (RTS) circuit (line) is raised, and if the asynchronous port needs to have its input stopped, it lowers the Request to Send (RTS) line. If the RTS line is lowered, it is assumed that the connected device will stop its output until RTS is raised. If is set, output occurs only if the Clear To Send (CTS) circuit (line) is raised by the connected device. If the CTS line is lowered by the connected device, output is suspended until CTS is raised. termiox Structure Related IOCTL Command The system calls that reference the structure have the form: Commands using this form are: The argument is a pointer to a structure. The current terminal parameters are fetched and stored into that structure. The argument is a pointer to a structure. The current terminal parameters are set from the values stored in that structure. The change is immedi- ate. Errors that can be returned include: The port does not support hardware flow control. The file descriptor for this port is configured for CCITT mode access. Hardware flow control is not allowed on CCITT mode devices. The argument is a pointer to a structure. The current terminal parameters are set from the values stored in that structure. The change occurs after all characters queued for output have been transmitted. This form should be used when changing parameters that affect output. Errors that can be returned include: The port does not support hardware flow control. The file descriptor for this port is configured for CCITT mode access. Hardware flow control is not allowed on CCITT mode devices. The argument is a pointer to a structure. The current terminal parameters are set from the values stored in that structure. The change occurs after all characters queued for output have been transmitted; all characters queued for input are discarded, then the change occurs. Errors that can be returned include: The port does not support hardware flow control. The file descriptor for this port is configured for CCITT mode access. Hardware flow control is not allowed on CCITT mode devices. AUTHOR
was developed by HP and AT&T. FILES
Files in or under SEE ALSO
ioctl(2), termio(7), modem(7). HP-PB Only termiox(7)
All times are GMT -4. The time now is 01:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy