Display number of occurrences for every character in an input string

PHP - 68 (or 39) bytes

<?foreach(count_chars(fgets(STDIN),1)as$k=>$v)echo chr($k)." : $v
";

Output for the example text:

  : 15
. : 1
T : 1
a : 10
c : 1
d : 4
e : 8
f : 2
g : 3
h : 3
i : 10
m : 1
n : 10
o : 4
p : 3
q : 1
r : 2
s : 5
t : 6
u : 1
x : 1
y : 1

If the exact output is not required, this would work for 39 bytes:

<?print_r(count_chars(fgets(STDIN),1));

Sample output:

Array
(
    [32] => 15
    [46] => 1
    [84] => 1
    [97] => 10
    [99] => 1
    [100] => 4
    [101] => 8
    [102] => 2
    [103] => 3
    [104] => 3
    [105] => 10
    [109] => 1
    [110] => 10
    [111] => 4
    [112] => 3
    [113] => 1
    [114] => 2
    [115] => 5
    [116] => 6
    [117] => 1
    [120] => 1
    [121] => 1
)

where each numerical index refers the ordinal value of the character it represents.

I suspect very strongly that using an in-built function that does exactly what the problem states will soon be disallowed.


k (8 7)

#:'=0:0

Example

k)#:'=:0:0
The definition of insanity is quoting the same phrase again and again and not expect despair.
T| 1
h| 3
e| 8
 | 15
d| 4
f| 2
i| 10
n| 10
t| 6
o| 4
s| 5
a| 10
y| 1
q| 1
u| 1
g| 3
m| 1
p| 3
r| 2
x| 1
c| 1
.| 1

edit: Down to seven, H/T Aaron Davies

Explanation

Take a String from keyboard :

k)0:0
text
"text"

Group the distinct elements and return a map containing key as distinct characters and values are the indices where the distinct elements occur.

k)=0:0
text
t| 0 3
e| ,1
x| ,2

Now count values of each entry in the map.

k)#:'=0:0
text
t| 2
e| 1
x| 1

GNU core utils - 29 22 20 chars (53 with formatting)

Wumpus's improvement (20 chars):

fold -1|sort|uniq -c

Firefly's improvement (22 chars):

grep -o .|sort|uniq -c

joeytwiddle's original (29 chars):

sed 's+.+\0\n+g'|sort|uniq -c

Originally I used sed to simply add a newline after each character. Firefly improved on that with grep -o ., since -o displays every matched pattern on its own line. Wumpus pointed out a further improvement using fold -1 instead. Nice work!

uniq does the real work, although it only applies to sorted lists.

Note that the output format does not exactly match the example in the question. That requires a final run through sed to swap the arguments. (Waiting on an answer to Jan Dvorak's question to see if this is required...)

Reformatting with sed is "only" another 33 characters! (Total 53)

|sed 's/ *\(.*\) \(.\)/\2 :  \1/'

Awk can almost do the job whilst adding only 25 chars, but it hides the first space. Silly awk!

|awk '{print $2" :  "$1}'

I wonder if improvements can be made in the reformatting stage...