Awk is such a weird tool--it's powerful and so few people know how to leverage it.<p>Yesterday, someone in chat wanted to extract special comments from their source code and turn them into a script for GDB to run. That way they could set a break point like this:<p><pre><code> void func(void) {
//d break
}
</code></pre>
They had a working script, but it was slow, and I felt like most of the heavy lifting could be done with a short Awk command:<p><pre><code> awk -F'//d[[:space:]]+' \
'NF > 1 {print FILENAME ":" FNR " " $2}' \
source/*.c
</code></pre>
This one command find all of those special comments in all of your source files. For example, it might print out something like:<p><pre><code> source/main.c:105 break
source/lib.c:23 break
</code></pre>
The idea of using //d[[:space:]]+ as the field separator was not obvious, like many Awk tricks are to people who don't use Awk often (that includes me).<p>(One of the other cases I've heard for using Awk is for deploying scripts in environments where you're not permitted to install new programs or do shell scripting, but somehow an Awk script is excepted from the rules.)