I have a python script that takes the text file as input(inputfile defined inside a python script) and does some calculation(myscript.py). Now i want to run the same python script(myscript.py) inside the shell script so i did like
python my_shell.sh
and i defined the input file a inputfile='data.txt'
inside the shell script.
(in simple language i need to run a python script over a data file but data file should be defined inside a shell script)
I tried a lot but i am getting error like
input file
1 2 3
4 5 6
7 8 9
10 11 12
c1 = np.loadtxt(inputfile)[:,0]
NameError: name 'inputfile' is not defined.
I hope i will get some solutions on this.Thanks.
import numpy as np
c1 = np.loadtxt(inputfile)[:,0]
c2 = np.loadtxt(inputfile)[:,1]
c3 = np.loadtxt(inputfile)[:,2]
def function(x):
c1,c2,c3 = x
d=(c1+c2+c3)
return d
print(function([c1,c2,c3]))
and inside the shell script i defined like this
#!/bin/sh
inputfile='data.txt'
python myscript.py