Printing bytes

Hi,

I have packed fields for which I am trying to print bytes. when I try cut -b2 it does print the 2nd byte besides that it also prints additional byte that I am not aware off:confused: data looks something like this

Input:
135
246

when I try cut -b2 it gives me

30
4A

but I need the output as

3
4

Weird... try: cut -b 2-2

doesnt help - Any other trick???

how 'bout:

LANG=C cut -b 2-2 myFile

still the same. :frowning:

Well, I am not sure why this is behaving like this with the packed decimal field????

Please show us the output of:

uname -a
locale

You do realize that a packed decimal field has bytes that are unprintable - assuming this is one of the IBM packed formats.

its AIX XXXXXXXXXXX 3 5 00C9C5204C00

LANG=en_GB
LC_COLLATE=en_GB
LC_CTYPE=en_GB
LC_MONETARY=en_GB
LC_NUMERIC=en_GB
LC_TIME=en_GB
LC_MESSAGES=en_GB
LC_ALL=

yes, I do understand that packed decimals would have unprintable characters. However, I was refering to the bytes in it. so, does that mean cut doesnt work with different formats?

Look at this thread. Reading hex data from assembler

see all the examples you have given are using cut but cut is the problem here.

The number 135 is stored as '13' '5F' or '5F' '13" (in packed decimal format) depending on whether is system is big endian or little endian.
To extract half of a byte to get '3' you need to display the field in hexadecimal as '1' '3' '5' 'F', which can be done using hexdump. Then use cut to extract the digit.

still doesnt help. when I do that I get 2 extra bytes

300
4AA

Post a sample of the data.

Ok, I get the issue here when the cut is printing it is printing the carriage return which is being displayed as { 0A} hex value. here is what I did. I captured the output of cut in a variable and displayed it using awk printf. this has solved my problem.

thank you all for all your time and effort.

very much apprectiate your efforts!!