Converting Between ASCII and EBCDIC

dd The first time I was handed an EBCDIC tape, I discovered the wonders of the standard UNIX utility dd. It is great for reading tapes generated on non-UNIX systems. (The GNU version of dd is on the tutorial.)

You do need to understand a bit about the blocking factors on the foreign tape , () but once you've got that down, you can handle just about anything.

For example, to read an EBCDIC tape on tape device /dev/rmt0 and convert it to ASCII, putting the output in file was_ibm:

% dd if=/dev/rmt0 of=was_ibm ibs=800 cbs=80 conv=ascii

dd reads standard input and writes to standard output, but if you want to specify file or device names, you can use the fairly non-standard if= and of= options to specify the input file and output file, respectively.

If you wanted to convert the other way, you could use this command:

% dd if=was_unix of=/dev/rmt0 obs=800 cbs=80 conv=ebcdic

There's also a conv=ibm option, which uses a different ASCII to EBCDIC conversion table. According to the dd manual page, "The ASCII/EBCDIC conversion tables are taken from the 256 character standard in the CACM Nov, 1968. The ibm conversion, while less blessed as a standard, corresponds better to certain IBM print train conventions. There is no universal solution."

Some gotchas:

One last thing to mention about dd: all options that refer to sizes expect counts in bytes, unless otherwise mentioned. However, you can use keyletters to indicate various types of multiplication: k means to multiply by 1024; b to multiply by 512 (a block); and w to multiply by 4 (word). You can also show an arbitrary multiplication by separating two numbers with an x.

- TOR