Comp-3 conversion possible with Shell Scripting or PERL?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comp-3 conversion possible with Shell Scripting or PERL?
# 1  
Old 03-28-2005
Comp-3 conversion possible with Shell Scripting or PERL?

I guess the subject asks it all, but I am wondering (before I go and code a COBOL module) if conversion of regular ASCII data to COMP-3 is possible on a UNIX environment (AIX 5.1)? Any help would be appreciated! Thanks, Dave
# 2  
Old 03-28-2005
If you are talking about "Packing" the data which is what COMP-3 does in COBOL then yes you will have to write a COBOL program to do that. I don't know of anything in UNIX that will do that without using COBOL. Of course I am not a UNIX expert so I could be wrong. Good Luck!
# 3  
Old 03-28-2005
Quote:
Originally Posted by jyoung
I don't know of anything in UNIX that will do that without using COBOL.
jyoung, meet ksh. This script will convert an integer argument to packed decimal.
Code:
#! /usr/bin/ksh
typeset -R1 dig
typeset -i8 octal
typeset -Z4 result

#
#  handle sign

number=$1
sign="C"
if ((number<0)) ; then
        ((number=-number))
        sign="D"
fi


#
#  prepend a zero if needed

((ilength=${#number}))
if ((ilength/2*2 == ilength)) ; then
        number=0${number}
        ((ilength=${#number}))
fi

#
#  conversion loop

((olength=ilength/2))
packswitch=1
char2=$sign
while ((ilength)) ; do
        dig=$number
        ((ilength=ilength-1))
        typeset -L$ilength newnumber=$number
        number=$newnumber
        if ((packswitch)) ; then
                char1=$dig
                octal=16#${char1}${char2}
                result=${octal#??}
                echo packing $olength $char1 $char2 $octal $result
                output[olength]=$(print -n \\${result})
                ((olength=olength-1))

        else
                char2=$dig
        fi
        ((packswitch=!packswitch))
done

#
#  output the packed decimal to prove it worked

olength=${#output[*]}
o=0
while ((o <= olength)) ; do
        print -n ${output[o]} | od -t x1
        ((o=o+1))
done

exit 0

# 4  
Old 03-28-2005
Thanks Per. I'm assuming this doesn't work for decimal data? Only true integers?

/home/rse0/xxgvlqr> /home/rse0/xxgvlqr/ascii_to_packed.ksh 123.45
packing 3 5 C 8#134 0134
/home/rse0/xxgvlqr/ascii_to_packed.ksh[39]: 16#.4: bad number
# 5  
Old 03-28-2005
With packed decimal, any decimal point is assumed. It is not stored in the data.
# 6  
Old 03-30-2005
Per, thanks very very much for your help. I think this will save me from having to write a COBOL routine. One more question: do you know of a way to put out "low-values" or "high-values" through a script. Basically we want our summary record to look like this:

high values positions 1-5
# of records in the file positions 6-10

Totaling the records, I can handle. LOL. Just need to know if there is a way to "write" low values or hgih values within a shell script. Thanks.
# 7  
Old 03-30-2005
So the total field is numeric rather than packed decimal? I think this should do it:
high5=$(print -n \\0377\\0377\\0377\\0377\\0377)

Define your total field like this:
typeset -Z5 total
to get the leading zeroes you will need.

Remember that ksh will add new line characters unless you supress them:
print -n ${high5}${total}

To test this:
Code:
$ cat x
#! /usr/bin/ksh
high5=$(print -n \\0377\\0377\\0377\\0377\\0377)
typeset -Z5 total
total=123
print -n ${high5}${total} | od -t x1
$  ./x
0000000   ff  ff  ff  ff  ff  30  30  31  32  33
0000012
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help required for Oracle database shutdown script conversion from shell to perl

Please tell me how to convert below program from shell script to perl. Same commands need to use in shutdown, just need program help for startup. export ORACLE_BASE=/home/oracle1 lsnrctl start lndb1 sqlplus '/ as sysdba' startup; (2 Replies)
Discussion started by: learnbash
2 Replies

2. Shell Programming and Scripting

shell or perl script needed for ldif file to text file conversion

This is the ldf file dn: sdcsmsisdn=1000000049,sdcsDatabase=subscriberCache,dc=example,dc=com objectClass: sdcsSubscriber objectClass: top postalCode: 29600 sdcsServiceLevel: 10 sdcsCustomerType: 14 givenName: Adelia sdcsBlackListAll: FALSE sdcsOwnerType: T-Mobile sn: Actionteam... (1 Reply)
Discussion started by: LinuxFriend
1 Replies

3. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

4. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

5. Shell Programming and Scripting

Conversion from Perl to Shell scripting

Hai ! I am doing a research on Bioinformatics and a part of the code in perl have to be converted to shell scripting. I am new to shell programming. Pls. kindly help me to convert this code to shell script though it is somewhat lengthy. PLS KINDLY HELP ME. THANKS IN ADVANCE. my @FreeEnergy =... (1 Reply)
Discussion started by: kswapnadevi
1 Replies

6. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

7. Shell Programming and Scripting

Linux/Unix shell scripting vs Perl

Hi, I have general question: i have good working Perl script with .pl extension, and now I have to migrate all to another Linux box, and I was told that I can use only shell scripting, so I'm not sure how different those two things are, will it work without any changes . Is there anything smart I... (6 Replies)
Discussion started by: trento17
6 Replies

8. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

9. Shell Programming and Scripting

Should I use PERL or Shell scripting?

Hello, I have done some BASIC shell scripting/PERL scripting before so I am familiar with the languages. I am not really sure which one would lend itself better to the application I have to write. I am required to scan the message logs for possible break in attempts. If I use shell scripting... (3 Replies)
Discussion started by: mojoman
3 Replies

10. UNIX for Dummies Questions & Answers

Another bash shell to perl conversion

Hello everyone. I am new to linux and need help again. I need help converting this bash shell to linux: for i in `ls -l *.txt` do `./cnvidtf.pl $i` `curl -u login:pswd --disable-espv -T loadfile.seq ftp://11.1.11.1` `mysql -u login -h 11.1.11.1 -ppswd < lddocs.sql` done Thanks! Any help... (6 Replies)
Discussion started by: freak
6 Replies
Login or Register to Ask a Question