0

I can print a byte from a string literal like: awk 'BEGIN {print "\001"}' | cat -v

But I need to print a byte of the result of a bitwise OR. So how can I print a byte from a number?

Gawk is ok.

sedwho
  • 5
  • 2

1 Answers1

3

You should be able to use the %c printf format specifier, I think:

$ mawk 'BEGIN {printf "%c\n", 3}' | cat -v
^C

$ LC_CTYPE=C gawk 'BEGIN {printf "%c\n", or(1,2)}' | cat -v
^C

The LC_CTYPE=C is probably only necessary with GNU awk, if your values may exceed a single byte in a locale that supports multi-byte characters.

steeldriver
  • 78,509
  • 12
  • 109
  • 152