ITEM: G1638L

Translate to EBCDIC from ASCII problems.


Question:

I have a RISC System/6000 running AIX 3.2.4 and I am trying to convert 
an ASCII file into an EBCDIC file.  When I do this with the dd command
the Carriage Return or Linefeed gets translated into what looks like a 
percent symbol(%).  All of my data is crammed into 80 character lines.  
How can I get this to work properly?

The command I used is as follows:

dd if=inputfile of=outputfile conv=EBCDIC

Response:

It appears that the ebcdic conversion being done by dd is correct.  dd is
converting LF (0x0A) to 0x25 which appears as a % in ASCII.  Carraige return
is not actually converted as it is the same in both ASCII and EBCDIC (0x0D). 
You probably wish to just delete the LF (as is done when you transfer files 
to a host with ftp).  Here is a script (I called convibm) that uses the dd 
ebcdic conversion table to convert an ASCII file to EBCDIC.  tr is used as 
a filter to delete the LF (0x0A) characters prior to translation by dd.

  \#!/bin/ksh
  tr -d '\\012' \< $1 | dd conv=ebcdic of=$1.ebcdic

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.

This second script uses sed is 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.  

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

Add execute permission for owner:  chmod u+x convibm2

To run: convibm2 INFILE

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

You could combine the two scripts if you need to make both changes:

  \#!/bin/ksh
  sed "s/\\[/`echo \\"\\\\0342\\"`/g
  s/\\]/`echo \\"\\\\0343\\"`/g" $1 | \\
  tr -d '\\012' | dd conv=ebcdic of=$1.ebcdic

NOTE: You have to do the sed first.  sed must have LF delimited records...


Support Line: Translate to EBCDIC from ASCII problems. ITEM: G1638L
Dated: January 1994 Category: N/A
This HTML file was generated 99/06/24~13:30:50
Comments or suggestions? Contact us