CLI search and replace in multiple files
Cristian Radulescu • March 11, 2010
In this example you have some text files (.txt) with urls like "http://example.com, http://another-example.com...". What you are trying to do is to replace all "http" references with "https".
You can find all text files using the following command in the directory where the files are located:
find -type f -name *.txt
You can execute a command on the search result using the -exec parameter for the find command:
find -type f -name *.txt -exec my_command
The actual search and replace will be performed using sed:
find -type f -name *.txt -exec sed -i 's/http/https/' {} \;