I have a bash script, f, that contains python code. That python code reads from standard input. I want to be able to call my bash script as follows:
f input.txt > output.txt
In the example above, the python code will read from input.txt and will write to output.txt.
I'm not sure how to do this. I know that if I wanted to just write to a file, then my bash script would look like this
#!/bin/bash
python << EOPYTHON > output.txt
#python code goes here
EOPYTHON
I tried changing the second line in the code above to the following, but without luck
python << EOPYTHON $*
I'm not sure how else to go about doing this. Any suggestions?
EDIT I'll give a more concrete example. Consider the following bash script, f
#!/bin/bash
python << EOPYTHON
import sys
import fileinput
for i in fileinput.input():
sys.stdout.write(i + '\n')
EOPYTHON
I want to run my code with the following command
f input.txt > output.txt
How do I change my bash script so that it uses "input.txt" as the input stream?