I'm assigning a variable as such:
cmd="sed -i 's/id="556"/id="33442233"\n pss="120"/g' a.xml"
But when im trying to print cmd im getting a syntax error, seems it's
because of multiple ' and "... how can I resolve this?
Use triple quotes:
cmd = '''sed -i 's/id="556"/id="33442233"\n pss="120"/g' a.xml'''
Btw. I see \n there - if you want to keep it as backslash-n and not have it converted to a single newline character, you can even use this:
cmd = r'''sed -i 's/id="556"/id="33442233"\n pss="120"/g' a.xml'''
worked for me:
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> cmd="sed -i \'s\/id=\"556\"\/id=\"33442233\"\n pss=\"120\"\/g\' a.xml"
>>> print cmd
sed -i 's\/id="556"\/id="33442233"
pss="120"\/g' a.xml