51.3 ASCII Characters: Listing and Getting ValuesMany UNIX systems come with a file named ascii -in a directory named something like /usr/pub or /usr/share/lib/pub . It's a list of the ASCII character set with the octal and hexadecimal value of each character. Here are two lines from the octal section:
|030 can|031 em |032 sub|033 esc|034 fs |035 gs |036 rs |037 us | |040 sp |041 ! |042 " |043 # |044 $ |045 % |046 & |047 ' |
It's saying, for instance, that an escape (
If your system doesn't have a file like that, you can type one in by
hand in a few minutes; start with a printed ASCII chart
or the
ascii
(7) or
ascii
(5) manual pages.
You might also want to make your own version and replace names like
Once you have that file, the following shell script, named ascii , can search for the octal value of a character. For example:
%
Remember to escape
special characters (
8.19
)
as I did with that ampersand (
The script makes a
sed
(
34.24
)
expression that exactly matches an entry in the first section of the
ascii
file (before the blank line that starts the hexadecimal section).
For example, the command
s/|
where stands for a space and
The
jot
(
45.11
)
command also translates a numeric value to the character it represents.
But
jot
doesn't show non-printable characters by name (like
- |
|