LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Convert a string from ASCII to EBCDIC (https://www.linuxquestions.org/questions/linux-general-1/convert-a-string-from-ascii-to-ebcdic-4175438715/)

Z038 11-26-2012 12:03 AM

Convert a string from ASCII to EBCDIC
 
I have some text files in EBCDIC that I want to add data to in EBCDIC.

I know I can use the dd commmand if I want to translate all the files from EBCDIC to ASCII, update it in ASCII, then convert it all back to EBCDIC. But I don't wish to do that in this case because many of the files have embedded binary data.

Right now I'm doing the following in a bash shell script to append a line in ASCII to $outfile (the output file):

Code:

echo './ ADD NAME='${1#./} >> "$outfile"
The ${1#./} is the input file name with the ./ stripped off the front of it. So if my script is passed a file name of ./XYZZY, it appends "./ ADD NAME=XYZZY" to the output file. The output file is mostly EBCDIC, so I'd like for that string to be in EBCDIC too, e.g., x'4b6140c1c4c440d5c1d4c57ee7e8e9e9e8'

Any ideas?

syg00 11-26-2012 02:18 AM

Whoa. That looks like you are building IEBUPDTE input.
Are we to presume you are doing this in zLinux as you don't seem to be concerned with little-endian <-> big-endian issues ?.

Z038 11-26-2012 09:19 AM

Yes, I am building IEBUPDTE input for an MVS 3.8J system running under the Hercules emulator on my home PC. I'm concatenating the contents of thousands of individual files on my PC into one file with an IEBUPDTE ADD statement in front of each one. I'm not concerned with little-endian vs big-endian issues since the data came from a big-endian system and is going back to one. It was downloaded as a binary file, so nothing has been translated or reordered.

I've thought of a way to do this, but it is a bit of a kludge. I'll be back with an update shortly.

Edit:

This appears to be giving me the result I was after. But it involves multiple file creation for each conversion, so it seems inefficient.

Code:

echo './ ADD NAME='${1#./} > tmp1
dd bs=80 cbs=80 conv=ebcdic,block if=tmp1 of=tmp2
dd bs=80 cbs=80 conv=unblock if=tmp2 of=tmp1
cat tmp1 $1 >> "$outfile"
rm tmp1 tmp2

If I could build the ADD NAME statement in EBCDIC directly in the script without having to write it to a file and convert it twice with dd, that would be an improvement.

syg00 11-26-2012 02:00 PM

Have you asked on the Yahoo Herc list ?. Used to be quite active, and all the devs are (were) subscribers.

Z038 11-26-2012 03:09 PM

That didn't occur to me, but it's a good idea. I'll do that.


All times are GMT -5. The time now is 07:14 AM.