xsv.el is a front end for CSV toolkit xsv. xsv provides very powerful ways to work with CSV file and xsv.el brings that awesomeness into Emacs.
For now, either clone the repo and add to load-path or use package manager like straight.
Emacs has CSV mode to work with CSV files, it has nice things but I find it lacking certain functionality I want and I have to resort to Numbers/Excel from time to time.
After I discovered the xsv, I realize it could bridge the gap I encountered before.
Some examples are:
- I want to filter the csv file to show only rows where certain columns match my criteria
- I want to only view columns I’m interested
xsv provides much more functionalities than I need, but I think I will bring in more and more into the package to make it even more useful.
Once package is loaded, run M-x xsv/filter
on a buffer visiting csv file or buffer
contain valid csv format content and it will ask for the input to be used for
filtering.
The input can contain multiple criteria and each criteria should be in one of these following syntax:
- columnA = ‘regexA’
- columnB != ‘regexB’
First one means search columnA where its value match regexA. Second form means search columnB where its value NOT match regexB.
In the case where column name contains spaces, you need to single quote it:
'transaction type' = 'debit'
You will always need to single quote the value.
Criteria can be joined by using &
like this:
columnA = 'regexA' & columnB = 'regexB' & columnC != 'regexC'
It means return rows where columnA matches regexA AND columnB matches regexB AND columnC NOT matches regexC.
The filtered result will be presented in a different buffer with prefix xsv-
so
the original buffer/file are left untouched.
Run M-x xsv/select
then enter the columns interested. Note you need to single quote the column name
if there is space in it. Also column names should be separated by ,
and there is NO space around the
separator. The column name is case sensitive.
For eg, this works:
Date,'Transaction Type'
This will NOT work (due to extra space after ,):
Date, 'Transaction Type'