Install sd Find And Replace Tool on Ubuntu 24.04

Install sd Find And Replace Tool on Ubuntu 24.04

The sd tool is a modern and more user-friendly alternative to the traditional sed command for finding and replacing text in files using regular expressions. It's designed to be simpler and more intuitive, especially for those who find sed syntax and usage challenging. This tutorial explains how to install sd find and replace tool on Ubuntu 24.04.

Install sd

Obtain the newest sd version directly from its GitHub repository:

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

Use the identified version to download sd:

wget -qO sd.tar.gz https://github.com/chmln/sd/releases/latest/download/sd-v$SD_VERSION-x86_64-unknown-linux-gnu.tar.gz

Create temporary directory and extract a tar.gz file:

mkdir sd-temp
tar xf sd.tar.gz --strip-components=1 -C sd-temp

Move the executable to the /usr/local/bin directory:

sudo mv sd-temp/sd /usr/local/bin

Execute the command to check the sd version:

sd --version

Remove no longer needed files:

rm -rf sd.tar.gz sd-temp

Testing sd

Create a simple file for testing:

printf '1\n2\n3\n4' > test.txt

The sd command enables the use of regular expressions to replace text within a file. For example, the following command can be used to replace newlines with commas:

sd '\n' ',' test.txt

Uninstall sd

To remove sd, delete the associated file:

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

Leave a Comment

Cancel reply

Your email address will not be published.