ITEM: F8831L

Problems converting from ASCII to EBCDIC with dd


We are using the AIX to AS/400 Connection Program Version 2 to 
communicate between our RISC System/6000 and AS/400 boxes. We have some 
reports that we are transfering to the AS/400, which must be converted 
from ASCII to EBCDIC. We have tried using

  dd if=text.ascii of=text.ebcdic conv=ebcdic


  dd if=text.ascii of=text.ebcdic conv=ibm

The conv=ibm is because in the man pages, we read that ibm is an IBM form
of the ebcdic type. This converts most of the text, but we are having 
problems with the '|', '[', and ']' symbols. They do not get converted. 
They don't always seem to convert to the same thing either. Is there 
something we can do to get around this problem?


You may want to investigate if the conversion function of the AS/400
Connection Program converts your ASCII programs properly.  Please
reference your AS/400 Connection Program documentation for further
details on converting ASCII to EBCDIC during file transfer.

dd makes the following conversions:

ASCII character    conv=ibm (in hex)     conb=ebcdic (in hex)
      [                   0xad                  0x4a
      ]                   0xbd                  0x4f
      |                   0x4f                  0x6a

Unfortunately, the ibm and ebcdic conversion tables are hardcoded in
dd and cannot be customized by the user...

Here is a script that uses the dd ebcdic conversion table to convert an
ASCII file to EBCDIC.  sed is used as a filter prior to calling dd in 
order to convert the square brackets to the ASCII characters that will 
convert properly to square brackets.  There is not an appropriate ASCII 
character that will convert to a split vertical bar with the dd ibm 
conversion table.  Thus, the script uses the ebcdic conversion table, 
which already converts the pipe symbol correctly.  I called the script 

  sed "s/\\[/`echo \\"\\\\0342\\"`/g
  s/\\]/`echo \\"\\\\0343\\"`/g" $1 | dd conv=ebcdic of=$1.ebcdic

Then add execute permission for owner:  chmod u+x convibm

To run: convibm INFILE

The script places the output in a file called INFILE.ebcdic where INFILE
is the name of the input file.

For example, a file called ascii contains the following:


If you run it through convibm with the following command: "convibm ascii"
an output file called ascii.ebcdic is created.  "od -x ascii.ebcdic" 
shows the following:

0000000  f0f1 f2f3 f4f5 f6f7 f8f9 8182 8384 8586
0000020  8788 8991 9293 9495 9697 9899 a2a3 a4a5
0000040  a6a7 a8a9 25a1 5a7c 7b5b 6c5f 505c 4d5d
0000060  6d4e 607e babb babb e0c0 d06a 6a5e 7d7a
0000100  7f6b 4b61 4c6e 6f25

                    \^\^   \^\^          \^ \^
                    ||   ||          | |
Notice that the square brackets have been correctly converted to 0xba and
0xbb and the pipe symbols have been converted to 0x6a (split vertical bar

Support Line: Problems converting from ASCII to EBCDIC with dd ITEM: F8831L
Dated: January 1994 Category: N/A
This HTML file was generated 99/06/24~13:30:51
Comments or suggestions? Contact us