How can I list unique characters used in a text file using linux command line tools?

character, linux, terminal, unique

Solution

I'd use `od`

od -cvAnone -w1

This lists characters, showing `\escapes` for non-displayables. Other formats are available

Examples:

So, to list the uniques:

od -cvAnone -w1 | sort -bu

Or to produce a top-20 histogram:

od -cvAnone -w1 | sort -b | uniq -c | sort -rn | head -n 20

See it Live On IdeOne

Problem

I would like to list a set of characters used in a text file using linux command line tools. How can I achieve this ? `uniq` utility works only on lines.

Original source