Python - using subprocess to call sed?

Viewed 22604

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.

2 Answers
Related