Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
169
rated 0 times [  169] [ 0]  / answers: 1 / hits: 174700  / 2 Years ago, sat, march 19, 2022, 8:56:43

I want to know how I can find and replace a specific text in multiple files like in Notepad++ in the linked tutorial.



e.g.: http://cybernetnews.com/find-replace-multiple-files/


More From » text-editor

 Answers
1

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" {} ;

[#41728] Sunday, March 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
horicgly

Total Points: 36
Total Questions: 126
Total Answers: 104

Location: Iceland
Member since Thu, Dec 1, 2022
1 Year ago
;