5

I'm writing a shell script with this command:

sed -e 's/OLD_ITEM/NEW_ITEM/g' 

But I actually want to do something that includes a directory:

sed -e 's/FOLDER/OLD_ITEM/NEW_ITEM/g'

How do ignore the forward slash so that the entire line FOLDER/OLD_ITEM is read properly?

Alex Harvey
  • 14,494
  • 5
  • 61
  • 97
Eric Brotto
  • 53,471
  • 32
  • 129
  • 174

3 Answers3

29

You don't have to use / as delimiter in sed regexps. You can use whatever character you like, as long as it doesn't appear in the regexp itself:

sed -e 's@FOLDER/OLD_ITEM@NEW_ITEM@g'

or

sed -e 's|FOLDER/OLD_ITEM|NEW_ITEM|g'
JesperE
  • 63,317
  • 21
  • 138
  • 197
7

You need to escape the / as \/.

The escape (\) preceding a character tells the shell to interpret that character literally.

So use FOLDER\/OLD_ITEM

codaddict
  • 445,704
  • 82
  • 492
  • 529
0

Escape it !

sed -e 's/FOLDER\/OLD_ITEM/NEW_ITEM/g'
Loïc Février
  • 7,540
  • 8
  • 39
  • 51