Table of Contents

How to replace in bulk a text in multiple file with a bash pipeline

About

This article is an example of a shell pipeline for data processing.

It will show you how to replace in bulk a text in multiple file.

Creation of the pipeline

Select the file that contains the text to replace

With grep, you can list the path of files containing a pattern

grep -rli 'old-text' *

where the options:

Replace the text in a file

With sed, you can replace an old text to a new one

sed -i 's/old-text/new-text/g' /file/path
# i: in place, the file will be overwritten

Put it together and create the pipeline

grep -rli 'old-text' * | xargs -i@ sed -i 's/old-text/new-text/g' @