In a file (.py file) I have some classes with different name but some have common variables:
class myClass1:
f1 = '512kB'
f2 = 2
f3 = 'something1'
class myClass2:
f1 = '512kB'
f2 = 6
f3 = 'something2'
I want to write a bash script and use SED to replace some strings. The problem is I want to first find myClass2 and then replace f1 = '512kB' with f1 = '1MB'
If I use
sed -i 's/f1 = '512kB'/f1 = '1MB'/g' /path/to/file
it will replace that string for both classes.
This assumes your class declarations are never indented.
However, given that this is Python, wouldn’t it make more sense to write a simple subroutine to set the variable’s value, rather than hard-code it?