grep to the rescue, again
Like most other areas of my life, this problem can be easily solved with a Linux one-liner centered around grep:
cat *.tex | grep -wo "[A-Z]\+\{2,10\}" | sort | uniq -c | sort -gr
Let's take a look at the pipeline:
- The cat *.tex outputs all my Latex to standard output.
- The grep -wo "[A-Z]\+\{2,10\}" matches whole words (the -w flag) that contain between 2 and 10 upper case letters. The -o flag returns only the match, not the entire line.
- The first sort sorts the acronyms, which is useful for the next step.
- The uniq gets rid of duplicates, but retains a counter because of the -c flag.
- Finally, the second sort sorts the entries numerically (-g) and reverses the results (-r).
Here's the output on my thesis:
292 IR
241 LDA
166 LSI
125 VSM
87 TCP
80 EM
35 APFD
34 SUT
29 HSD
22 TOPIC
22 II
18 MALLET
16 LOC
14 PS
14 OR
14 IDE
12 CALLG
11 ICA
10 RNDM
10 MAP
10 KL
10 CS
...
Note that this command works with any text file; it is not unique to Latex. Just change the cat command.