Run shell command with variable in filename via Python
Posted
by
rajitha
on Super User
See other posts from Super User
or by rajitha
Published on 2012-06-05T18:09:12Z
Indexed on
2012/06/06
10:43 UTC
Read the original article
Hit count: 211
python
|shell-script
I have files with naming convention
st009_out.abc1.dat
st009_out.abc2.dat
st009_out.abc3.dat
..................
..................
I am writing Python code where I want to use data from the file to perform a math function and need to extract the second column from the file. I have tried it this way:
for k in range(1,10):
file1=open('st009_out.abc'+str(k)+'.dat','r')
...........
os.system("awk '{print $2}' st009_out.abc${k}.pmf > raj.dat")
but this is not working as it is not taking the value of k
in the shell command.
How do I progress?
© Super User or respective owner