Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Octal value conversion

Status
Not open for further replies.

awelch

Technical User
Apr 24, 2002
85
US
I need a way to convert an ASCII character (the % sign) to it's corresponding octal value (045) on the unix platform.

I have attempted to do this conversion using the following unix commands, and I haven't had any success.
sed, tr.

Here is a sample of the data file: (octal dump)
0000120 0 0 0 9 0 * 0 * P * % \n G S * H
060 060 060 071 060 052 060 052 120 052 045 012 107 123 052 110



And here is what I am looking for:
0000120 0 0 0 5 2 * 0 * P * \0 \0 \0 % \n G
060 060 060 065 062 052 060 052 120 052 000 000 000 045 012 107

The file was originally created on an hp-3000, which allowed for the use of octal values (control values). The program that produced this output would write out the value using the following clause: pic s9(04).

I have also tried to do the conversion using micro focus cobol, but as far as I can tell, mfc does not like octal values.

So, let me know if you know of a unix command that will change the value.

Thanks for your assistance in advance.

 
man bc? Sorry I'm not at a *nix machine right now, so I can't verify exactly.
 
To get the ascii value of "%" as a 3-digit octal number...

[tt]printf "%03o" %[/tt]
 
man ascii

quite useful..

Vgor's post is very good, I didn't think in that
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top