Install sq Structured Data Processing Tool on Ubuntu 26.04

Install sq Structured Data Processing Tool on Ubuntu 26.04

The sq is a command-line tool that provides a simple way to query structured data sources, including SQL databases and formats such as CSV and Excel. It works with different data sources, making it easy to inspect, filter, query, and transform data from the terminal. This tutorial explains how to install sq structured data processing tool on Ubuntu 26.04.

Install sq

Retrieve version number of the most recent sq release:

SQ_VERSION=$(curl -s "https://api.github.com/repos/neilotoole/sq/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')

Download the corresponding archive and extract the sq executable directly into /usr/local/bin:

curl -sSL https://github.com/neilotoole/sq/releases/latest/download/sq-$SQ_VERSION-linux-amd64.tar.gz \
  | sudo tar xz -C /usr/local/bin sq

Once the binary has been installed, confirm that sq is available by displaying its version:

sq --version

Testing sq

For a quick test, create a sample CSV file containing several records:

echo -e 'name,age\nJohn,25\nJames,29\nOliver,35\nEmma,31' > test.csv

Load the CSV file into sq using the add command and assign it the @csv_data handle:

sq add --handle @csv_data ./test.csv

The data can then be queried with expression. The following command selects the name field from every row:

sq '@csv_data.data | .name'

Output:

name
John
James
Oliver
Emma

Uninstall sq

When sq is no longer required, remove its executable from the system:

sudo rm -rf /usr/local/bin/sq

The sq cache and configuration directories can also be deleted with:

rm -rf ~/{.cache,.config}/sq

Leave a Comment

Cancel reply

Your email address will not be published.