在python中使用sed命令
如何在python中为长linux命令使用subprocess.call()。如果我想通过在linux shell中用空格替换所有逗号来编辑文件call records.txt,我可以:在python中使用sed命令,python,linux,Python,Linux,如何在python中为长linux命令使用subprocess.call()。如果我想通过在linux shell中用空格替换所有逗号来编辑文件call records.txt,我可以: tr ',' ' ' < records.txt tr',''
tr ',' ' ' < records.txt
tr',''
如何在subprocess.call()中将其与python一起使用。
谢谢records.txt:
jflaskdzhuskajkdkhdsa,dakssdsd,s,a,sa,sas,s,,sas,wwq,wq,wq,w,q,wq,wq,,wq,wq,e,d,rdsa,s,aa,ews,,WQD,AS,SA,WRFDSS,
python文件:
import subprocess
subprocess.call("tr \',\' \' \' < records.txt", shell=True)
python有什么问题吗?我只是尝试在python和linux之间进行转换command@AvinashRaj在我的例子中,我需要对文件进行复杂的文本操作,但我还需要访问Python程序中的一些变量。在这种情况下,在Python程序中运行
sed
是我的最佳选择。谢谢。但是我不明白为什么我们需要shell=True?shell参数(默认为False)指定是否使用shell作为要执行的程序。如果shell为True,建议将args作为字符串而不是序列传递。在shell=True的Unix上,shell默认为/bin/sh。如果args是字符串,则该字符串指定要通过shell执行的命令。这意味着字符串的格式必须与在shell提示下键入时的格式完全相同。欲了解更多信息,请访问:-
jflaskdzhuskajkdkhdsa dakssdsd s a sa sas s sas wwq wq wq w q wq wq wq wq e d rdsa s aa ews WQD AS SA WRFDSS