The first issue is shell=True
that is used together with a list argument. Either drop shell=True
or use a string argument (the complete shell command) instead:
from subprocess import check_call
check_call(["sed", "-i.orig", regex])
otherwise the arguments ('-i.orig'
and regex
) are passed to /bin/sh
instead of sed
.
The second issue is that you haven't provided input files and therefore sed
expects data from stdin that it is why it appears to hang.
If you want to make changes in files inplace, you could use fileinput
module:
#!/usr/bin/env python
import fileinput
files = ['/Users/user1/Desktop/phenotypes2'] # if it is None it behaves like sed
for line in fileinput.input(files, backup='.orig', inplace=True):
print re.sub(r'\.*131006', '201335658-01 13100', line),
fileinput.input()
redirects stdout to the current file i.e., print
changes the file.
The comma sets sys.stdout.softspace
to avoid duplicate newlines.