There is a file with following text:
CXX_FLAGS = -fPIC -Wall -Wextra -Wno-missing-braces -ffloat-store -pthread -std=gnu++17
To replace the string "-std=gnu++17" with "-std=c++17 -std=gnu++17", I tried:
sed -i -e 's/\-std\=gnu\+\+17/\-std=c\+\+17 \-std=gnu\+\+17/g' filename
That however does not work, until I remove the \ escape from frst + sign in search expression. So these seem to be OK:
sed -i -e 's/\-std\=gnu++17/\-std=c\+\+17 \-std=gnu\+\+17/g' filename
sed -i -e 's/\-std\=gnu+\+17/\-std=c\+\+17 \-std=gnu\+\+17/g' filename
sed -i -e 's/\-std\=gnu..17/\-std=c\+\+17 \-std=gnu\+\+17/g' filename
I understand the + must be escaped when not in character class, but I thought one can prefix any character with backslash in regex. Why does escaping the + sign here cause the search-replace to fail?
The OS is Ubuntu 20.04 LTS.