Anh Anh - 6 months ago 26
Linux Question

Use sed command in python

How to use subprocess.call() in python for long linux command. Like if I want to edit a file call records.txt by replacing all the comma with whitespace in linux shell, I can:

tr ',' ' ' < records.txt


How to use that with python in subprocess.call().
Thanks

Answer

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 file:

import subprocess
subprocess.call("tr \',\' \' \' < records.txt", shell=True)

output:

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
Comments