0

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' {} \;

2
  • If you're using GNU sed, \? in a basic regular expression means 'match the previous thing 0 or 1 times', not a literal question mark. (This is a GNU extension to normal BRE syntax) Commented Jun 16, 2021 at 0:18
  • And \( \) is a capturing group; not sure if that's intentional or you want to match literal parens. Commented Jun 16, 2021 at 0:19

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.