This sounds like a variation on [this question](http://unix.stackexchange.com/questions/39039/get-text-file-word-occurrence-count-of-all-words-print-output-sorted/39041#39041).

So I'll work on that answer:

 for w in `cat test.tex`; do echo $w; done|sort|egrep '\\[a-z]*{'|uniq -c
 1 A}&\multicolumn{2}{c|}{Cavity
 1 \begin{figure}[H]
 1 \begin{minipage}[b]{.46\textwidth}
 1 \begin{tabular}{|c|cS|cS|}
 1 \begin{tikzpicture}[remember

The regular expression may need some work but this should get you started.