codeacola
codeacola

Reputation: 11

SED Command Not Working To Replace String in PHP files

I am trying to replaced a string in all php files with an empty string and it just seems to be ignoring it all together... No errors, yet nothing is replaced in the files.

could someone tell me what is wrong with this command?

find ./ -type f -name '*.php' -exec sed -i 's/session_save_path\('tcp\:\/\/redis\.domain\.com\:6379\?auth\=secret'\);/ /g' {} \;

Upvotes: 0

Views: 239

Answers (1)

BarathVutukuri
BarathVutukuri

Reputation: 1303

This should work

find . -type f -name '*.php' -exec sed -i "s/session_save_path('tcp:\/\/redis.domain.com:6379?auth=secret')//g" {} \;

You need not escape braces in sed, because sed uses BRE regex.

Instead of using / as delimiter, one can use any character except \

# Using # as delimiter for the sed command
# / after tcp need not be escaped as it isn't the delimiter

find . -type f -name '*.php' -exec sed -i "s#session_save_path('tcp://redis.domain.com:6379?auth=secret')##g" {} \;

Learn more about BRE, ERE regex here

Upvotes: 1

Related Questions