Install trdsql on Ubuntu 26.04

Install trdsql on Ubuntu 26.04

The trdsql is a command-line tool that allows SQL queries to be executed against CSV, LTSV, JSON, and other tabular data formats. It provides a convenient way to inspect, filter, and transform structured files using SQL syntax. This tutorial explains how to install trdsql on Ubuntu 26.04.

Prepare environment

The unzip package is needed to unpack the trdsql archive downloaded from GitHub.

sudo apt update
sudo apt install -y unzip

Install trdsql

Determine the newest trdsql release version available on GitHub:

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

Download the archive corresponding to the detected release version:

curl -sSLo trdsql.zip https://github.com/noborus/trdsql/releases/latest/download/trdsql_v${TRDSQL_VERSION}_linux_amd64.zip

Extract the trdsql binary directly into /usr/local/bin:

sudo unzip -jq trdsql.zip '*/trdsql' -d /usr/local/bin

Confirm that the trdsql binary is available by displaying its version:

trdsql --version

Once the installation has been completed, delete the downloaded archive:

rm -rf trdsql.zip

Testing trdsql

A small CSV file can be used to confirm that trdsql is functioning correctly. Create a sample file with several records:

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

Run an SQL query against the CSV file and return the name column:

trdsql -ih -oat 'SELECT name FROM test.csv'

The command produces the following output:

+--------+
|  name  |
+--------+
| John   |
| James  |
| Oliver |
| Emma   |
+--------+

The -ih option treats the first CSV row as the header, while -oat formats the query result as an ASCII table.

Uninstall trdsql

If the trdsql is no longer required, remove binary from the system:

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

If unzip was installed specifically for this procedure and is no longer needed, it can also be removed:

sudo apt purge --autoremove -y unzip

Leave a Comment

Cancel reply

Your email address will not be published.