What you are describing could very well be the result of an ear mite infection. Ear mites generally are associated with a dark, waxy build-up in the ear canal. The irritation they cause can lead to pain and discomfort for your cat, which then leads to scratching at the ear or shaking the ear.
Take a few minutes to read the description of an ear mite infection from a recent issue of my blog, Questions On Dogs and Cats, at: http://questionsondogsandcats.blogspot.com/search/label/Ear%20Mites
You can gently clean the ear to remove some of this waxy material, but you will still need to use some medicine to ultimately kill the mites.
NOTICE: The information provided on this site is not a substitute for professional medical advice,
diagnosis, or treatment. Never delay or disregard seeking professional medical advice from your
physician or other qualified health provider because of something you have read on Wellsphere.
If you have a medical emergency, call your doctor or 911 immediately.