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 using data from different databases. The CSV files are then 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.
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.
Hence, I just need to:
- press C-u M-s o (or the equivalent but longish of C-u M-x occur)
- type the string I am looking for
- hit RET
It doesn’t get easier than this.