Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape the forward slash in a sed command [duplicate]

Tags:

sed

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?

like image 573
Eric Brotto Avatar asked Nov 28 '22 05:11

Eric Brotto


1 Answers

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'
like image 106
JesperE Avatar answered Jan 11 '23 23:01

JesperE