views:

30

answers:

3

Hello wonderful computing persons,

This is really simple and I hope I'm not being redundant. 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?

+2  A: 

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
A: 

Escape it !

sed -e 's/FOLDER\/OLD_ITEM/NEW_ITEM/g'
Loïc Février
+6  A: 

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