pythonsed-e表达式#1:char 11:unterminated';s';命令

pythonsed-e表达式#1:char 11:unterminated';s';命令,python,shell,sed,Python,Shell,Sed,我在python中执行shell命令时遇到问题。以下是导致错误的部分代码: p = subprocess.Popen(["cat input.txt |apertium -d. kaz-morph|\ sed -e 's/\$\W*\^/$\n^/g'| cut -f2 -d'/'|cut -f1 -d '<'|\ awk '{print tolower($0)}'|sort -u>output.txt"], shell=True, stdout=f1) p=sub

我在python中执行shell命令时遇到问题。以下是导致错误的部分代码:

p = subprocess.Popen(["cat input.txt |apertium -d. kaz-morph|\
    sed -e 's/\$\W*\^/$\n^/g'| cut -f2 -d'/'|cut -f1 -d '<'|\
    awk '{print tolower($0)}'|sort -u>output.txt"], shell=True, stdout=f1)
p=subprocess.Popen([“cat input.txt | apertium-d.kaz morph|\

sed-e的s/\$\W*\^/$\n^/g'| cut-f2-d'/'| cut-f1-d'
'\n'
必须是
'\\n'
,否则它被解释为一个换行符,这将导致一个未终止的字符串
“cat input.txt”\apertium-d.kaz morph | sed-e/\$\W*/$”


或者,将字符串标记为原始:
r“cat input.txt | apertium。。。。“

此外,使用
shell=True
,只需一个字符串就可以了,不需要使用字符串列表。将该脚本放在单独的文件中可能会更干净,例如
~/morph和sort.sh
和do
chmod+x~/morp和sort.sh
并将python更改为
Popen(“~/morp和sort.sh”],shell=True,stdout=f1)