EBCDIC to ASCII conversion


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users EBCDIC to ASCII conversion
# 8  
Old 03-22-2019
l would add to all that has already been said:
i worked 5 years end 80 but mostly early 90s with such files, as said EBCDIC, EBC, ASCII are not a format, COMP2 is a data format, only IT IS OF NO USE TO KNOW THAT, if you have no idea of the data structure, worse, this looks like a COBOL file, and COBOL file, you have to know the data structure AND the type, in those days I used to work with indexed files, but once I ruined one of the most important files of the site because I was given the structure, but on one told me it was a random file...
So sorry but we cannot help you with the information you have given so far, but I believe what you are looking for is a still in activity COBOL programmer you will have to pay for a week... because this is not an easy task depending on the file structure and organisation
# 9  
Old 03-22-2019
Quote:
There is no copybook (whatever that is)
Copybooks are used in same way that the include statement is used in php, or the ". filename" is used in bash.
# 10  
Old 03-22-2019
FYI "packed format" is not part of the EBCDIC character set, it is a way of storing numerical data on the host. Basically the host has two forms of storing numerical data: "zoned (decimal)" and "packed (decimal)". Here is a thorough description.

Basically "zoned" stores a hexadecimal value in the lower nibble (the lower 4 bits of a byte) and an "F" in the higher nibble. In the last digit the higher nibble is used for storing the sign instead. i.e "123" (or "+123") would look like F1F1C3, the "C" being the code for a positive number. This format can be translated easily into ASCII (simply replace the high-nibbles with "3" instead of "F").

The packed format stores a digit in each of the nibbles so that there is no direct translation of one byte EBCDIC to one byte ASCII. The sign is stored in in the last nibble but coded in various ways (depending on "format" versus "informat". Either "C" is positive and "D" is negative (format) or "A", "C", "E" and "F" is positive and "B" and "D" is negative (informat). If you end with an odd number of nibbles the leftmost byte is padded with a 0 (zero) in the high-nibble. You actually need to calculate the value from the bytewise representation to translate it to ASCII.

There are professional software packages for the file transfer between (z/OS) mainframes and the UNIX world. Connect: Direct, IND$FILE and XCOM Data Transfer, just to name a few. The problem with transferring mainframe data is that there are a lot more data formats on the mainframe than there are on UNIX. You have i.e. fixed-length-record data, you have packed and zoned decimals and lots more. It isn't (only) that easy 1:1 translation you have from one charset to another.

I hope this helps.

bakunin
# 11  
Old 03-22-2019
I'm fully familiar of what packed decimal and zoned decimal are. But knowing how to interpret fields encoded in those formats if you don't know record boundaries and field boundaries is a wild guessing game.

I didn't know that a copybook was another language's name for what the C language calls an include file (thank you jgt).

Fortunately, I haven't had to use COBOL since 1975. I'm also fully aware that the UNIX dd utility was a joke showing how versatile UNIX utilities were and could even be made to use operands that were familiar to programmers used to writing IBM System 360 Job Control Language (JCL) card decks instead of all of the supposedly "confusing" single letter utility options used on most UNIX utilities. If you've never written JCL, the JCL DD statements described where various input and output files were to be found and/or placed for whatever job was to be run by that JCL deck and, especially if the file resided on a magnetic tape, the size of the blocks that were to be read from or written to the device used to access that file. Unfortunately (or fortunately, depending on how much you like JCL), the utility proved very useful when transferring files between UNIX systems and mainframes and we're still stuck with that syntax today.

But enough of this digression.

swapna_1990 has a file containing some EBCDIC text and some packed decimal, zoned decimal, or other binary data mixed in and wants it converted to ASCII text and "normal data" that is readable. Whether that data comes from a mainframe or from a C program written on a UNIX, Linux, or BSD system doesn't really matter. If you don't know the format of the data you're reading including field lengths or separators, field types, and record lengths or separators; then you don't know how to process that data. Until we get the data format from swapna_1990's customer, there is nothing we can do to guess at how that data could be extracted nor what tools might need to be used to do so. The fact that it came from a mainframe makes a COBOL program an obvious guess at something that might work. But from what we know so far, if swapna_1990 is extremely lucky, it is possible that a dd command coupled with output piped through some awk code might be able to work wonders. (Not highly likely, but there is a chance.)
# 12  
Old 03-22-2019
Hi...

I decided to see which printable ASCII characters would appear in a 'cat /path/to/packed_decimal_filename.ext' and came to the conclusion that without even a hint of a sample there is literally no way of helping...
Code:
#!/bin/bash
# EBCDIC.sh

# These are all the PRINTABLE ASCII ONLY characters generated by "EBCDIC" packed numbers.
# Note this does NOT include byte value 0, NULL; Ctrl characters; extended characters above decimal 128.

# Upper 4 bits BCD 2 to 7.
for high_nibble in {2..7}
do
    # Lower 4 bits BCD 0 to 9.
    for low_nibble in {0..9}
    do
        decimal=$(( low_nibble+(high_nibble*16) ))
        printf "Low nibble = %d, high nibble = %d, decimal = %d,    character = " $low_nibble $high_nibble $decimal
        printf \\x$( printf "%02x" "$decimal" )".\n"
    done
done

Results, OSX 10.14.3, default bash terminal:
Code:
Last login: Fri Mar 22 20:31:10 on ttys000
AMIGA:amiga~> cd Desktop/Code/Shell
AMIGA:amiga~/Desktop/Code/Shell> ./EBCDIC.sh
Low nibble = 0, high nibble = 2, decimal = 32,    character =  .
Low nibble = 1, high nibble = 2, decimal = 33,    character = !.
Low nibble = 2, high nibble = 2, decimal = 34,    character = ".
Low nibble = 3, high nibble = 2, decimal = 35,    character = #.
Low nibble = 4, high nibble = 2, decimal = 36,    character = $.
Low nibble = 5, high nibble = 2, decimal = 37,    character = %.
Low nibble = 6, high nibble = 2, decimal = 38,    character = &.
Low nibble = 7, high nibble = 2, decimal = 39,    character = '.
Low nibble = 8, high nibble = 2, decimal = 40,    character = (.
Low nibble = 9, high nibble = 2, decimal = 41,    character = ).
Low nibble = 0, high nibble = 3, decimal = 48,    character = 0.
Low nibble = 1, high nibble = 3, decimal = 49,    character = 1.
Low nibble = 2, high nibble = 3, decimal = 50,    character = 2.
Low nibble = 3, high nibble = 3, decimal = 51,    character = 3.
Low nibble = 4, high nibble = 3, decimal = 52,    character = 4.
Low nibble = 5, high nibble = 3, decimal = 53,    character = 5.
Low nibble = 6, high nibble = 3, decimal = 54,    character = 6.
Low nibble = 7, high nibble = 3, decimal = 55,    character = 7.
Low nibble = 8, high nibble = 3, decimal = 56,    character = 8.
Low nibble = 9, high nibble = 3, decimal = 57,    character = 9.
Low nibble = 0, high nibble = 4, decimal = 64,    character = @.
Low nibble = 1, high nibble = 4, decimal = 65,    character = A.
Low nibble = 2, high nibble = 4, decimal = 66,    character = B.
Low nibble = 3, high nibble = 4, decimal = 67,    character = C.
Low nibble = 4, high nibble = 4, decimal = 68,    character = D.
Low nibble = 5, high nibble = 4, decimal = 69,    character = E.
Low nibble = 6, high nibble = 4, decimal = 70,    character = F.
Low nibble = 7, high nibble = 4, decimal = 71,    character = G.
Low nibble = 8, high nibble = 4, decimal = 72,    character = H.
Low nibble = 9, high nibble = 4, decimal = 73,    character = I.
Low nibble = 0, high nibble = 5, decimal = 80,    character = P.
Low nibble = 1, high nibble = 5, decimal = 81,    character = Q.
Low nibble = 2, high nibble = 5, decimal = 82,    character = R.
Low nibble = 3, high nibble = 5, decimal = 83,    character = S.
Low nibble = 4, high nibble = 5, decimal = 84,    character = T.
Low nibble = 5, high nibble = 5, decimal = 85,    character = U.
Low nibble = 6, high nibble = 5, decimal = 86,    character = V.
Low nibble = 7, high nibble = 5, decimal = 87,    character = W.
Low nibble = 8, high nibble = 5, decimal = 88,    character = X.
Low nibble = 9, high nibble = 5, decimal = 89,    character = Y.
Low nibble = 0, high nibble = 6, decimal = 96,    character = `.
Low nibble = 1, high nibble = 6, decimal = 97,    character = a.
Low nibble = 2, high nibble = 6, decimal = 98,    character = b.
Low nibble = 3, high nibble = 6, decimal = 99,    character = c.
Low nibble = 4, high nibble = 6, decimal = 100,    character = d.
Low nibble = 5, high nibble = 6, decimal = 101,    character = e.
Low nibble = 6, high nibble = 6, decimal = 102,    character = f.
Low nibble = 7, high nibble = 6, decimal = 103,    character = g.
Low nibble = 8, high nibble = 6, decimal = 104,    character = h.
Low nibble = 9, high nibble = 6, decimal = 105,    character = i.
Low nibble = 0, high nibble = 7, decimal = 112,    character = p.
Low nibble = 1, high nibble = 7, decimal = 113,    character = q.
Low nibble = 2, high nibble = 7, decimal = 114,    character = r.
Low nibble = 3, high nibble = 7, decimal = 115,    character = s.
Low nibble = 4, high nibble = 7, decimal = 116,    character = t.
Low nibble = 5, high nibble = 7, decimal = 117,    character = u.
Low nibble = 6, high nibble = 7, decimal = 118,    character = v.
Low nibble = 7, high nibble = 7, decimal = 119,    character = w.
Low nibble = 8, high nibble = 7, decimal = 120,    character = x.
Low nibble = 9, high nibble = 7, decimal = 121,    character = y.
AMIGA:amiga~/Desktop/Code/Shell> _

As one can see unless we have the EXACT format of the file then there is no way on earth to decode it.
There are some 'Ctrl' characters, ; binary 0 - NULL; a few in the _extended_ASCII_ region.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

EBCDIC to ASCII conversion

Hi, I have a input file which is EBCIDIC and it has packed decimals. Can anyone help me to convert EBCIDIC file to ASCII(Need to convert even Packed decimal values also to normal format). Thanks swapna (12 Replies)
Discussion started by: swapna_1990
12 Replies

2. Shell Programming and Scripting

Need help for EBCDIC TO ASCII conversion through UNIX

Hi All , We have a mainframe file which is in EBCDIC format.We dont have direct access to mainframe ,client has provided us the mainframe file in unix box.The mainframe file is containing pact data(COMP1 ,COMP2 etc) which are unreadble.Can anyone suggest me how to convert this kind of ebcdic... (7 Replies)
Discussion started by: STCET22
7 Replies

3. UNIX for Advanced & Expert Users

Conversion from EBCDIC to Ascii OR unicode

I have a file in my Unix ( SOLARIS ) with EBCDIC format...I want this file to read in ASCII OR unicode...Is it possible with UNIX to convert this file on ASCII OR UNICODE format from EBCDIC format? I was searching through web and found only conversion table :( Request Rejected Below is... (16 Replies)
Discussion started by: joshilalit2004
16 Replies

4. UNIX for Dummies Questions & Answers

EBCDIC TO ASCII Conversion through UNIX Command

Hi All , I have a mainframe file which contains the data in EBCDIC unreadable format.I have downloaded this raw unreadable file from mainframe system to windows in text format then I pushed to Unix system.Now I want to convert this file to ASCII readable format file in unix.Can anyone advise me... (2 Replies)
Discussion started by: STCET22
2 Replies

5. Programming

Ebcdic to ascii

Hi, I want to convert ebcdic values to ascii values. Are there anyany specific c++ libraries with g++ compiler, which can do it ? gcc version 4.1.2 20080704 (Red Hat 4.1.2-54) (19 Replies)
Discussion started by: tostay2003
19 Replies

6. UNIX for Advanced & Expert Users

Conversion of data - ebcdic to ascii

Hi, I want to convert ebcdic values to ascii values. Are there anyany specific c++ libraries with g++ compiler, which can do it ? gcc version 4.1.2 20080704 (Red Hat 4.1.2-54) (0 Replies)
Discussion started by: tostay2003
0 Replies

7. Shell Programming and Scripting

EBCDIC Format to ASCII

Hi, we have source file with EBCDIC format(Main Frame files) where we receving from source system. I would like to convert the EBCDIC format file to unix systemformat(ex: .csv,txt ) I have wrote script like: dd if=<SRCPATH>yyy.xxx.RB065 of=<SRCPATH>/output.csv ibs=800 cbs=80... (8 Replies)
Discussion started by: koti_rama
8 Replies

8. Solaris

EBCDIC to ASCII Binary conversion issue on Solaris i-series Unix

Hi All, I am facing EBCDIC to ASCII Binary conversion on Solaris i-series Unix system. However this is working fine on Solaris Sparc Unix system. Input file having EBCDIC format does not work on Solaris i-series Unix system. Could you please tell me, what will be the root cause for same? (14 Replies)
Discussion started by: amodkavi
14 Replies

9. UNIX for Dummies Questions & Answers

Conversion from EBCDIC to ASCII

when i try to convert a mainframe EBCDIC file to ASCII ,i dont see correct file this is the source file ... (3 Replies)
Discussion started by: venkatvelpula
3 Replies

10. Shell Programming and Scripting

ascii to ebcdic conversion

Hello, I need a program for ascii to ebsdic conversion. If anybody can help, it'll be greatly appreciated. Thanks. (1 Reply)
Discussion started by: er_ashu
1 Replies
Login or Register to Ask a Question