SED rename
5 March, 2021 by
SED rename

A very simple solution: replace in all *.txt files in folder string_1 with string_2:

sed -i 's/string_1/string_2/g' *.txt


Here I use sed to replace every occurrence of the word “cybernetnews” with “cybernet” in every file with the extension, c, in the directory, /home/user/directory/.

find /home/user/directory -name \*.c -exec sed -i "s/cybernetnews/cybernet/g" {} \;

A more generic variation where you search recursively from the directory of execution and operate on only regular, readable, writeable files:

find ./ -type f -readable -writable -exec sed -i "s/cybernetnews/cybernet/g" {} \;