How to find and replace every occurrence of
httpaccess
with
httpaccessabc
in every file of name "access.html" in a particular folder
shopt -s globstar
sed -i.bak 's/httpaccess/&abc/g' **/access.html
globstar
with **
to match your filename, recursively. sed -i
to perform an in-place substitution. This will create backup files with a suffix .bak
. To unset the shell option, use shopt -u globstar
afterwards.
find
is your friend
find . -type f -name 'access.html' \
-exec sed -i.bak 's/httpaccess/&abc/g' {} \;
Edit
To replace whole pattern use :
find . -type f -name 'access.html' \
-exec sed -i.bak 's/abcde/wazsde/g' {} \;
Notes
.
with /your/path
of concern. \\
at the end of first line is just to split the command into two lines for more readability. g
option with sed s
command is for global substitution. If you know the folder for access.html then :-
sed -i.bak 's/httpaccess/httpaccesabc/g' access.html
(or)
sed -i.bak 's/httpaccess/&abc/g' access.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.