Reputation: 55
How to find and replace every occurrence of
httpaccess
with
httpaccessabc
in every file of name "access.html" in a particular folder
Upvotes: 1
Views: 840
Reputation: 111
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
Upvotes: 1
Reputation: 21965
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.Upvotes: 2
Reputation: 74645
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.
Upvotes: 2