Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'd like to be able to run

unicode-names 'abç'

and see the corresponding Unicode character names:

LATIN SMALL LETTER A
LATIN SMALL LETTER B
LATIN SMALL LETTER C WITH CEDILLA

Printing a string as a series of Unicode glyph names would be useful in several cases:

  • Distinguish easily confused characters such as "i" and "í".
  • Explain what a literal string actually contains (for example non-printable or unassigned, zero-width characters).
share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

The uniutils package has the program uniname.

$ echo -n …—|uniname
character  byte       UTF-32   encoded as     glyph   name
    0          0  002026   E2 80 A6       …      HORIZONTAL ELLIPSIS
    1          3  002014   E2 80 94       —      EM DASH
share|improve this answer
    
For minimal output with only the names, use these options: echo -n …— | uniname -bcegpu –  l0b0 Mar 19 '12 at 7:53
add comment

I don't know a good way to check this from bash, but Python has a built-in Unicode database which you can use like in a script like this:

#!/usr/bin/env python
import sys, unicodedata
for ch in sys.stdin.read().decode('utf-8'):
  try:
    print unicodedata.name(ch)
  except ValueError:
    print 'codepoint ', ord(ch)

You can use this script like this (assuming you called it unicode-names):

$ echo 'abc©áοπρσ' | unicode-names
LATIN SMALL LETTER A
LATIN SMALL LETTER B
LATIN SMALL LETTER C
COPYRIGHT SIGN
LATIN SMALL LETTER A WITH ACUTE
GREEK SMALL LETTER OMICRON
GREEK SMALL LETTER PI
GREEK SMALL LETTER RHO
GREEK SMALL LETTER SIGMA
codepoint 10

The database throws a ValueError exception for any characters it doesn't know about, so we print their codepoints in decimal (these are unprintable characters, usually).

Caveat: the script assumes your terminal is UTF-8 encoded. If it isn't, you should change the argument of the decode() method. Python supports a very wide selection of encodings, yours will definitely be in there.

share|improve this answer
    
Better -- use sys.getdefaultencoding(). –  Chris Down Mar 15 '12 at 21:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.