Your pipeline changes no files. It pulls out lines that matches the regular expression using grep
, then changes that data, but does not attempt to make changes in any files.
Instead, assuming GNU sed
:
find ~/dev_web/_site -type f \
-exec grep -qF 'http://localhost:4000' {} ';' \
-exec sed -i 's#http://localhost:4000#https://another.site#g' {} +
This would find all regular files in or under the directory ~/dev_web/_site
. For each such file, grep
first tests whether the file contains the given string. If it does, GNU sed
is invoked to make an in-place substitution.
The grep
step could be omitted, but GNU sed
would update the modification timestamp on all files without it.
You may want to only look in a subset of the files in the directories beneath ~/dev_web/_site
. If this is the case, restrict the search with something like -name '*.js'
(or whatever name pattern you want to match) just after -type f
.
Adding -print
just before -exec sed ...
would print the pathnames of the files that find
would give to sed
.
Related: