I'm trying to append some data after a matching pattern with sed. In bash it works fines. When i tried to run the same command in a python script, nothing is being appended.
The file's content:
Code:
# directive as shown below:
This is a configuration file.
In bash when i run sed, it works fine:
Code:
[root@centos ~]# sed -i '/^# directive* /a cfg_dir=\/etc\/nagios\/commands' count
[root@centos ~]# cat count
# directive as shown below:
cfg_dir=/etc/nagios/commands
This is a configuration file.
The python code:
Code:
test = ['command', 'local', 'test']
os.chdir('/root')
for t in test:
sp.run(f"sed -i '/^# directive shown below* /a cfg_dir=\/etc\/nagios\/testing' count", shell=True)
Nothing's changed:
Code:
[root@centos ~]# python3 test.py
[root@centos ~]# cat count
# directive as shown below:
This is a configuration file.
I just don't get it.