コマンドラインでASCIIコード表を作る

ascii-table

odコマンドでASCIIコード表を作ります。
odの-taオプションを使うと、ダンプ時に文字コードの場合は文字を、制御コードの場合は制御の種類を表示することができます。

~$ echo -ne "\x0" | od -ta
0000000 nul
0000001
~$ echo -ne "\x1b" | od -ta
0000000 esc
0000001
~$ echo -ne "\x41" | od -ta
0000000   A
0000001
~$ 

ベースになるコマンドとしてはodの他には、seqとperlです。

~$ seq 0 127 | perl -ne 'print chr' | od -ta
0000000 nul soh stx etx eot enq ack bel  bs  ht  nl  vt  ff  cr  so  si
0000020 dle dc1 dc2 dc3 dc4 nak syn etb can  em sub esc  fs  gs  rs  us
0000040  sp   !   "   #   $   %   &   '   (   )   *   +   ,   -   .   /
0000060   0   1   2   3   4   5   6   7   8   9   :   ;   <   =   >   ?
0000100   @   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O
0000120   P   Q   R   S   T   U   V   W   X   Y   Z   [   \   ]   ^   _
0000140   `   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o
0000160   p   q   r   s   t   u   v   w   x   y   z   {   |   }   ~ del
0000200
~$ 

まず、左側のアドレスがデフォルトでは8進表示です。これを16進にするには、-Axオプションを使います。それから、アドレスは2桁で良いのでcutしておきます。

~$ seq 0 127 | perl -ne 'print chr' | od -ta -Ax | cut -b5-
00 nul soh stx etx eot enq ack bel  bs  ht  nl  vt  ff  cr  so  si
10 dle dc1 dc2 dc3 dc4 nak syn etb can  em sub esc  fs  gs  rs  us
20  sp   !   "   #   $   %   &   '   (   )   *   +   ,   -   .   /
30   0   1   2   3   4   5   6   7   8   9   :   ;   <   =   >   ?
40   @   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O
50   P   Q   R   S   T   U   V   W   X   Y   Z   [   \   ]   ^   _
60   `   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o
70   p   q   r   s   t   u   v   w   x   y   z   {   |   }   ~ del
80

ヘッダ(\ 0〜f)を付けて末尾の空行(80〜)を削除します。

~$ echo -n "\ ";printf " %3x" `seq 0 15`;echo;seq 0 127 |
> perl -ne 'print chr'|od -ta -Ax | cut -b5- | head -n -1
\    0   1   2   3   4   5   6   7   8   9   a   b   c   d   e   f
00 nul soh stx etx eot enq ack bel  bs  ht  nl  vt  ff  cr  so  si
10 dle dc1 dc2 dc3 dc4 nak syn etb can  em sub esc  fs  gs  rs  us
20  sp   !   "   #   $   %   &   '   (   )   *   +   ,   -   .   /
30   0   1   2   3   4   5   6   7   8   9   :   ;   <   =   >   ?
40   @   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O
50   P   Q   R   S   T   U   V   W   X   Y   Z   [   \   ]   ^   _
60   `   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o
70   p   q   r   s   t   u   v   w   x   y   z   {   |   }   ~ del
~$ 

これで完成です。

白黒が味気ないなあと思ったら、以下のようにhtmlに書き出してみましょう。ランダムで色を決めてますので、運が良ければ冒頭の画像のようなHTMLが出来上がります。

~$ (echo -n "\ ";printf " %3x" `seq 0 15`;echo;
> seq 0 127 | perl -ne 'print chr' | od -ta -Ax -v |
> cut -b5- | head -n -1 ) | perl -pe 'BEGIN{print"<TABLE border=1>"};
$c=sprintf("#%06x",int rand 0xffffff);
s|([^\s]+)|<TD bgcolor=$c>$1</TD>|g;
s|^(.*)$|<TR>$1</TR>|;END{print"</TABLE>"}' > a.html

6 responses to “コマンドラインでASCIIコード表を作る

  1. Ꮇerely desired to ѕtate I am thrilled tɦat i came onto ʏour site! http://bit.ly/2da3Q7F

  2. Many thanks, this website is very valuable. http://tinyurl.com/jjl3tn9

  3. I needed to compose you the tiny word to finally give many thanks yet
    again over the extraordinary solutions you have documented on this site.
    This is simply generous with you giving extensively just what numerous people could possibly have marketed for an e book to get some cash for their
    own end, even more so since you could have done it if you ever decided.
    These advice likewise acted like the fantastic
    way to fully grasp other individuals have the same eagerness really like my own to learn way more with regards
    to this condition. I am certain there are numerous more fun occasions in the future for
    many who look over your blog post. https://www.youtube.com/watch?v=fJd9oeS4mpk

  4. That’s an expert answer to an inittesreng question

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA