ASCII to EBCDIC - DD command

Posted on 2006-07-24
Medium Priority
Last Modified: 2013-12-06
I'm using the DD command in UNIX to convert ASCII to EBCDIC so that I can print via "lp" to a AS/400 attached printer.  I'm using the AS/400 as a print server.  The command below works fine except that the carriage return/line feed disappear.  The file prints without the carriage return line feed.

Here is the unix command:
cat $file | dd ibs=80 cbs=132 conv=ebcdic | lp -d AS400PRNT -s

Not that it should matter, but I'm running this under HPUX.
Question by:javajws
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 57

Expert Comment

ID: 17172918
have you tried:

    dd if=$file ibs=80 cbs=132 conv=ebcdic | lp -d AS400PRNT -s

Does the file have CRLF in it?  Normally on UNIX records are terminated by LF only.

Author Comment

ID: 17175492
Using the IF parameter does help with the CRLF but the length of the file is 132 instead of 80.  I'm guessing this is because of using the CBS of 132.  When I use a CBS of 80, the CRLF disappears again.

I also tried using the "iconv" UNIX command to convert from ascii to ebcdic:
iconv -f roma8 -t cp037 $file | lp -d AS400PRNT -s

and I get the same results.  No carriage return/line feed.
LVL 57

Expert Comment

ID: 17175849
What happens if you use cbs=82?

Is each line in the file actually 80 bytes long?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 17176169
It still prints landscape and the CRLFs are not correct.
LVL 57

Expert Comment

ID: 17176471
Does the input file contain CRLF to start with?
LVL 57

Accepted Solution

giltjr earned 2000 total points
ID: 17176494
O.K. try

  dd if=$file ibs=80 cbs=132 conv=ebcdic ofs=printit
   lp -d AS400PRNT -s printit
LVL 57

Expert Comment

ID: 17176622
I did a couple of quick tests.  The dd command does not add CRLF, so if the original file does not have them in there, they won't be afterwards.  They must exist before hand.

Also, the ibs and cbs are not LRECL's, but "blocksize", which is the number of bytes that will be read and then converted at a time.  This does not make the dd command treat the input as if it was 80 byte records and write 132 byte records.
LVL 14

Expert Comment

ID: 17185318
As giltjr stated above, Unix files usually have only LF and not CR. Most Unixen have a 'unix2dos' or (for HP-UX) 'ux2dos' command to add the CR.

That would get you
  unix2dos < file | dd ... | lp ...

If your system doesn't have this command you can also write it pretty trivially in awk, sed, perl, whatever. Here is a version in awk
   awk '{ printf "%s\r\n", $0; }'

Expert Comment

ID: 17188524

Have you tried 'conv=ibm' in you dd command.

IBM use a varient of ebcdic !! AS/400 is IBM tech stack - just a thought


Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question