can simplify by avoiding use of extended regex, only *
needs to be escaped in this case
$ cat ip.txt
'generic_raid': {'keys': 5 * (1000**3)
$ sed "s/'generic_raid': {'keys': 5 \* (1000\*\*3)/'generic_raid': {'keys': 2/g" ip.txt
'generic_raid': {'keys': 2
not required in this case, but if "
is undesirable and '
features in pattern, ascii code \x27
can be used
$ sed 's/\x27generic_raid\x27: {\x27keys\x27: 5 \* (1000\*\*3)/\x27generic_raid\x27: {\x27keys\x27: 2/g' ip.txt
'generic_raid': {'keys': 2
Also, a perl
solution which has a \Q
feature helpful in these cases:
$ perl -pe "s/\Q'generic_raid': {'keys': 5 * (1000**3)/'generic_raid': {'keys': 2/" ip.txt
'generic_raid': {'keys': 2
From perldoc
Returns the value of EXPR with all the ASCII non-"word" characters
backslashed. (That is, all ASCII characters not matching
/[A-Za-z_0-9]/ will be preceded by a backslash in the returned string,
regardless of any locale settings.)