Install grex on Ubuntu 20.04

Install grex on Ubuntu 20.04

The grex is a command line tool and library for creating Perl compatible regular expressions (PCRE) from user given test cases. The grex outputs a regular expression that only match given test cases. So grex can be used to find an initial regular expression that can be improved manually.

This tutorial demonstrates how to install grex on Ubuntu 20.04.

Install grex

Get the latest version tag of grex release from GitHub. Assign version tag to variable.

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

Run the following command to download tar.gz file from releases page of the grex repository:

sudo wget -qO grex.tar.gz "https://github.com/pemistahl/grex/releases/latest/download/grex-v${GREX_VERSION}-x86_64-unknown-linux-musl.tar.gz"

Extract a tar.gz file to /usr/local/bin directory.

sudo tar xf grex.tar.gz -C /usr/local/bin

Now grex command can be used for all users as system-wide command.

We can check grex version as follows:

grex --version

Remove unnecessary file:

rm -rf grex.tar.gz

Testing grex

Run the grex command and provide test cases as arguments:

grex james john jessica

In this case, command outputs the following regular expression:

^j(?:essica|ames|ohn)$

The grex command can read test cases from a file as well. Create test.txt file:

printf "james\njohn\njessica\n" > test.txt

Run the grex command with -f option:

grex -f test.txt

Uninstall grex

If you want to completely remove grex, delete related file:

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

Leave a Comment

Cancel reply

Your email address will not be published.