Run shell command with variable in filename via Python
- by rajitha
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?