emulating ".ascii" with Awk

Charles C. Bennett ccb at decvax.UUCP
Fri Jan 24 10:54:05 AEST 1986


Tricky, I don't think awk will do it.
Write a little shell script.

use "od -b" to break the string into bytes in octal
use "sed 's/^.......[ ]*//' to strip addresses from the od output
use tr to convert the spaces in the od output to newlines
prepend the string "ibase=8" to the stuff you have so far
feed the works to the stdin of "bc"
use tr to convert the newlines to commas
use sed to strip the telltale trailing comma

something like:

bc $TMPFILE <<!
ibase=8
`echo $STRING|od -b|sed 's/^.......[ ]*//'|tr ' ' '\012'`
!
echo `cat $TMPFILE|tr '\012' ','`|sed 's/,$//'

the final pipeline leaving the result on stdout.

A 'C' program to do this is trivial.

decvax!ccb



More information about the Comp.unix mailing list