It never occurred to me


Years of Emacs, and I am still learning something new that improves my daily workflow. Recently I’ve had to deal with CSV files, generated by a little Clojure program which extracts data from different databases and produces some CSV files to be imported in another database through a new shiny application bought by our customer. Data integration, exactly.

While the data extraction is just a matter of SQL queries, the CSV files must match the stringent requirements of the new application. We ended up with messy CSV files, close but not that close to the expected results. Needless to say, sometimes we have to edit the files manually, and this is where Emacs once again shines.

The problem is simple: how can I list only the matches I am looking for in a CSV file, without printing the whole lines the matches belong to? I need a clean list of occurrences, nothing more, because debugging these files is already painful as it is.

I am so used to swiper-isearch and counsel-rg I tend to forget Emacs built-in occur. As per the documentation:

When NLINES is a string or when the function is called interactively with prefix argument without a number (`C-u' alone as prefix) the matching strings are collected into the *Occur* buffer by using NLINES as a replacement regexp.

So all is needed is pressing C-u M-s o (the equivalent of C-u M-x occur in my Emacs configuration), typing the string I am looking for and hitting RET. It doesn’t get easier than this.