The xsv is a command line based CSV processor which allows to search, slice, split, join, sort, or perform other operations on CSV data.
This tutorial shows how to install xsv on Ubuntu 20.04.
Install xsv
Get the latest version tag of xsv release from GitHub and assign version tag to variable.
XSV_VERSION=$(curl -s "https://api.github.com/repos/BurntSushi/xsv/releases/latest" | grep -Po '"tag_name": "\K[0-9.]+')
Download tar.gz
file from releases page of the xsv repository:
curl -Lo xsv.tar.gz "https://github.com/BurntSushi/xsv/releases/latest/download/xsv-${XSV_VERSION}-x86_64-unknown-linux-musl.tar.gz"
Extract a tar.gz
file to /usr/local/bin
directory.
sudo tar xf xsv.tar.gz -C /usr/local/bin
Now xsv
can be used for all users as system-wide command.
We can check xsv version:
xsv --version
We can remove unnecessary tar.gz
file:
rm -rf xsv.tar.gz
Testing xsv
Create simple CSV file:
echo -e 'name,age\nJohn,25\nJames,29\nOliver,35\nEmma,31' > test.csv
The xsv supports various operations. For example, we can use table
argument to display aligned output of CSV data:
xsv table test.csv
Output:
name age
John 25
James 29
Oliver 35
Emma 31
The count
argument allows to count the rows in a CSV file.
xsv count test.csv
Output:
4
We can search the rows for particular field using regular expression. For example, the following command finds all rows in a CSV file where name
field starts with letter J.
xsv search -s name '^J' test.csv
You will get the following output:
name,age
John,25
James,29
Testing xsv
If you decided to completely remove xsv, delete related file:
sudo rm -rf /usr/local/bin/xsv
The 1 Comment Found
Muchas Gracias for the post. has been very helpful
Leave a Comment
Cancel reply