아래 명령은 bash에서 정상적으로 실행됩니다.bash in python : sed unterminated s command
/folk/vlm/commandline/./vlmTool find -l all | grep -e "^Target ID" -e "City" -e "Zone" | sed "s#.*City.*#&\n#g" > new.txt
는하지만 파이썬에서 내가 얻을 같은 명령을 실행하려고하면
['sed', 's#.*City.*#&\n#g']
**sed: -e expression #1, char 12: unterminated `s' command**
코드 :
\n
시퀀스는 대한 이스케이프 시퀀스로 파이썬으로 이해된다
#!/usr/local/bin/python -tt
import subprocess
import shlex
cmd = '/folk/vlm/commandline/./vlmTool find -l all | grep -e "^Target ID" -e "City" -e "Zone" | sed "s#.*City.*#&\n#g" > new.txt'
cmd2= "/folk/vlm/commandline/./vlmTool find -l all"
args1 = shlex.split(cmd2)
cmd3 = 'grep -e "^Target ID" -e "City" -e "Zone"'
args2 = shlex.split(cmd3)
cmd4 = 'sed "s#.*City.*#&\n#g"'
args3 = shlex.split(cmd4)
print args3
p1 = subprocess.Popen(args1, stdout=subprocess.PIPE)
p2 = subprocess.Popen(args2, stdin=p1.stdout, stdout=subprocess.PIPE)
p3 = subprocess.Popen(args3, stdin=p2.stdout, stdout=subprocess.PIPE)
p1.stdout.close()
p2.stdout.close()
output = p3.communicate()[0]
'[sed', r 's #. * City. * # & \ n # g ']'시도하십시오. – SethMMorton