Monday, May 6, 2024
19
rated 0 times [  19] [ 0]  / answers: 1 / hits: 9201  / 1 Year ago, fri, december 2, 2022, 10:59:51

I use the grep command to search for a string in many files. Is there something similar to "search and replace"?


More From » command-line

 Answers
5

You are looking for the sed command. For example, to replace the "dog" with "cat" in all text files in the current directory:



sed -i 's/dog/cat/' *.txt

[#40605] Saturday, December 3, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hical

Total Points: 498
Total Questions: 106
Total Answers: 117

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
hical questions
Sun, May 9, 21, 00:59, 3 Years ago
Fri, Jun 25, 21, 03:06, 3 Years ago
Thu, May 19, 22, 15:32, 2 Years ago
;