Somewhy replace empty chars (space, tab, etc.) is not working with sed and regexp grouping:
sed -i "s|dir(\s*)=(\s*)'${site_path_source}'|dir$1=$2'${site_path_target}'|g"
The whole line does replace a string in a file:
sudo find "${config_path}" -type f -exec sed -i "s|dir(\s*)=(\s*)'${site_path_source}'|dir$1=$2'${site_path_target}'|g" {} \;
Any idea how to fix it?
Thanks!
EDIT1: Now using -r to enable extended regular expressions, but still doesn't replace:
sudo find "${config_path}" -type f -exec sed -ir "s|dir(\s*)=(\s*)'${site_path_source}'|dir$1=$2'${site_path_target}'|g" {} \;
But still doesn't do the replace.
EDIT2 (WORKING SOLUTION): When using \( \) for grouping, it WORKS:
sudo find "${config_path}" -type f -exec sed -i "s|dir\(\s*\)=\(\s*\)'${site_path_source}'|dir\1=\2'${site_path_target}'|g" {} \;
But I don't understand, why the EDIT1 solution with -r extended regular expressions is not working.
EDIT3 (WORKING SOLUTION2): Using -r to enable extended regular expressions, it WORKS NOW:
sudo find "${config_path}" -type f -exec sed -r -i "s|dir(\s*)=(\s*)'${site_path_source}'|dir$1=$2'${site_path_target}'|g" {} \;
Explanation:
- Using "sed -ir SUFFIX" is wrong, because -i needs a suffix.
- Using "sed -r -i SUFFIX" is GOOD, because -r and -i are used separately, and -i is followed by a suffix.