Quantcast
Channel: Ian Chilton » Linux
Viewing all articles
Browse latest Browse all 7

Find and replace across multile files, recursivly

$
0
0

In a previous post, I gave a command for doing a find and replace operation across multiple files in a directory.

I have used that command a number of times over the years but the problem with it is that it only works if all of the files you want to change are in the same directory.

I sometimes have need to perform this find and replace operation across files in different directories.

For this, you can use the find command and use xargs to run sed:

find . -name '*.txt' -print0 | xargs -0 sed -i 's|originaltext|replacementtext|g'

This command will find any files with the .txt extension, in the current directory or any directory below it and run it through sed to replace ‘originaltext’ with ‘replacementtext’.


Viewing all articles
Browse latest Browse all 7

Trending Articles