0

I have few thousand files with a href tag as follows:

href="../../../../file/old.html

I am trying to remove this from all the files. I have tried sed but it throws an error and fails.

sed -i '/href="../../../../file/old.html"/c\' *.html 
sed: -e expression #1, char 11: unknown command: `.'

Suggestions please...

Sunshine
  • 479
  • 10
  • 24

1 Answers1

2

Your expression is not entirely correct. You need to say sed 's/pattern/replacement/g' file. Or, using another delimiter if / is in the pattern and you don't want to escape it, sed 's#pattern#replacement#g' file (or any other).

Also, the usage of \ may mislead sed, since it escapes the character after it. If you want a literal one, you have to escape it.

So you need to say something like:

sed 's#href="../../../../file/old.html"#c\\#g' file
#                                         ^
#            double \ so that you have a literal \

Let's test it:

$ cat a
hello <a href="../../../../file/old.html">bye</a>
hehehe
$ sed 's#href="../../../../file/old.html"#c\\#g' a
hello <a c\>bye</a>
hehehe
Community
  • 1
  • 1
fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • Spoke too soon. It didn't change. I had opened the html file in an editor, but it did say there's been a change and ask for a reload.. – Sunshine Jun 07 '16 at 12:30
  • sed -i 's#href="../../../../file/old.html"##g' - This worked all file.! – Sunshine Jun 07 '16 at 12:37