Problem using os.system() with sed command

后端 未结 7 2070
耶瑟儿~
耶瑟儿~ 2020-12-20 04:30

I\'m writing a small method to replace some text in a file. The only argument I need is the new text, as it is always the same file and text to be replaced.

I\'m hav

相关标签:
7条回答
  • 2020-12-20 05:11

    Maybe some indentation problem?

    The following works correctly:

    import os
    
    def updateExportConfigId(id):
        stringId = "%s" % id
        cmd= "sed '1,$s/MANAGER_ID=[0-9]*/MANAGER_ID=" + stringId + "/g' test.dat > test.new"
        print "command is " + cmd
        os.system(cmd)
    
    
    updateExportConfigId("adsf")
    

    Also do not use reserved words (id) as variables.

    0 讨论(0)
提交回复
热议问题