Solved

ASCII to EBCDIC - DD command

Posted on 2006-07-24
9
3,792 Views
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.
0
Comment
Question by:javajws
9 Comments
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
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.
0
 
LVL 9

Author Comment

by:javajws
Comment Utility
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.
0
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
What happens if you use cbs=82?

Is each line in the file actually 80 bytes long?
0
 
LVL 9

Author Comment

by:javajws
Comment Utility
It still prints landscape and the CRLFs are not correct.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 57

Expert Comment

by:giltjr
Comment Utility
Does the input file contain CRLF to start with?
0
 
LVL 57

Accepted Solution

by:
giltjr earned 500 total points
Comment Utility
O.K. try

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

Expert Comment

by:giltjr
Comment Utility
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.
0
 
LVL 14

Expert Comment

by:chris_calabrese
Comment Utility
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; }'
0
 
LVL 6

Expert Comment

by:JJSmith
Comment Utility

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

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

Cheers
JJ
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now