I`m trying to replace a html from several files using sed without sucess. I need to replace this:
<link rel='shortcut icon' href='/admin/img/favicons/favicon.ico' type='image/x-icon'>
with this:
<link rel="icon" href="/admin/img/logo.svg">
This is the last command i tried, but always gives errors:
#find . -type f -name "*.php" -exec sed -i'' -e 's/<link rel='shortcut\ icon' href='\/admin\/img\/favicons\/favicon.ico' type='image/x-icon'>/<link rel\="icon" href\="admin/img/logo.svg">/g' {} +
sed: -e expression #1, char 42: unknown option to `s'
can you please help?
'
inside your sed script with'\''
(end-quote, escaped quote, start-quote). Or wrap the sed script in double-quotes instead of single-quotes, and escape the double-quotes in the replacement text with\"
...unlike single-quotes, you can escape double-quotes.$' ... '
to quote the sed script instead of just' ... '
. This may have other side-effects as it changes how the shell interprets text inside the quotes. – cas Nov 19 '21 at 01:51xmlstarlet
. – Kusalananda Nov 19 '21 at 06:53find
andsed -i
while you're still trying to get something to work. At best it probably won't break your source code too much, but until you know the edit expression does what you really want it to do there's a strong possibility it will warp your files beyond repair. Instead, use an instance ofsed
that operates on just a single file, and reivew its output carefully – Chris Davies Nov 19 '21 at 10:13