The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Another bash shell to perl conversion freak UNIX for Dummies Questions & Answers 6 05-29-2008 02:04 PM
bash to perl conversion thumper Shell Programming and Scripting 2 07-14-2006 04:36 PM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 09:12 AM
Perl conversion & perldoc question thumper Shell Programming and Scripting 2 09-11-2005 10:24 PM
Conversion of bash parsing script to perl? cstovall Shell Programming and Scripting 2 10-13-2004 11:33 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-28-2005
dfran1972 dfran1972 is offline
Registered User
  
 

Join Date: Jan 2004
Posts: 10
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 (permalink)  
Old 03-28-2005
jyoung jyoung is offline
Registered User
  
 

Join Date: Nov 2001
Location: Flint, MI
Posts: 228
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 (permalink)  
Old 03-28-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,127
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 (permalink)  
Old 03-28-2005
dfran1972 dfran1972 is offline
Registered User
  
 

Join Date: Jan 2004
Posts: 10
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 (permalink)  
Old 03-28-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,127
With packed decimal, any decimal point is assumed. It is not stored in the data.
  #6 (permalink)  
Old 03-30-2005
dfran1972 dfran1972 is offline
Registered User
  
 

Join Date: Jan 2004
Posts: 10
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 (permalink)  
Old 04-14-2005
dfran1972 dfran1972 is offline
Registered User
  
 

Join Date: Jan 2004
Posts: 10
Quote:
Originally Posted by Perderabo
With packed decimal, any decimal point is assumed. It is not stored in the data.
Per, need some more help. Noting your quote above, we have a field that is signed (see below) that I need to put into comp-3 format. Any ideas? I know you said the decimal is implied, but what about handling a positive or negative number?

+000000000050408

or

-000086214050408
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:34 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0