02/01/2023 12:15 | Category: bash

Tags: linuxtipsedbash

running sed with multiple file names or types

When running sed if we have a replacement that is present across multiple files we can add some OR clauses to our operation.

Example sed call using multiple file types

In the below example we're using multiple available file types with our sed call.

NOTE: The below command will run, this is NOT a dry run command.

find . -type f \( -name '*.<my file extension>' -o -name 'example.txt' -o -name 'other-example.tf' \) -readable -writable -exec sed -i 's/<search string>/<replace string>/g' {} \;

The key portion to pay attention to is:

-type f \( -name 'something.here' -o -name 'something-else.here' \)

Note that the spaces between our -type f and -name are very important, as well as the trailing space before our delimeter.