-2

I accidentally added this line:

tazadeg2018/test2018/g

many many ways to multiple files by a wrong use of sed where i just wanted to change a word in multiple files.

Now I tried to remove the lines containing this word with something like:

find . -type f -exec sed -i 's/tazadeg2018/test2018/g//g' {} \;

But it doesn't work saying: sed: -e expression #1, char 28: unknown option to `s'

I guess this is due to the many forward-slashes that have a special meaning in sed. So if anyone knows how to remove this line in multiple files I'd be super happy:)

Robin Kohrs
  • 575
  • 4
  • 13
  • Using the `s` command like this will turn those added lines into blank lines; is what what you want, or do you actually want to delete those lines? Also, do you have a backup of these files? If you get this correction wrong, you risk making things even worse (or at least, even harder to clean up). Make a backup first, and test anything you do to make sure it's actually going to do what you want. – Gordon Davisson Mar 21 '21 at 18:15

1 Answers1

0

you get this error because you ask sed to use / as separator, and as your string contains slashes, it just mess up the sed command.

You don't have to usr / within sed command; try using , for example:

find . -type f -exec sed -i 's,tazadeg2018/test2018/g,,g' {} \;

see How to insert strings containing slashes with sed?

OznOg
  • 3,908
  • 2
  • 25
  • 32