I wish to call sed from python using subprocess. The script I tried using is below. however, this pipes the sed output to the standard terminal. It seems that the '>' operator is not recognised from within my subprocess.call statement. Any suggestions?
import sys
import os
import subprocess
files = os.listdir(sys.argv[1])
count = 0
for f in files:
count += 1
inp = sys.argv[1] + f
outp = '../' + str(count) + '.txt'
sub = subprocess.call(['sed', 's/\"//g', inp, '>', outp])
Also - my file names have spaces in them, i.e., " file1 .txt". Could this be the issue? My sed command works fine when I call sed from the terminal, just not from the script.
Thanks.
Use
It would be much faster to skip running all the sed processes and just do the work in Python
This will run considerably faster, since it won't fork a lot of subprocesses.