[英]Execute a python file in a bash file and read two text file
I have a python file which works fine. 我有一个工作正常的python文件。 It takes a file and does something on it.
它需要一个文件并对其执行某些操作。 So I run it like this:
所以我这样运行:
./MyPy.py File.txt
./MyPy.py File.txt
Then with bash script I grep some part of it. 然后,使用bash脚本,我将其部分复制。
./MyPy.py File.txt |
./MyPy.py File.txt | grep -vE "^color"
grep -vE“ ^ color”
So what I want to do is creating a bash file which asks the user for the path of the File and does ./MyPy.py File.txt | 因此,我想做的是创建一个bash文件,该文件要求用户提供文件的路径并执行./MyPy.py File.txt | grep -vE "^color" in it and gives the result to out put.
grep -vE“ ^ color”放入其中,并将结果输出。
Can you please help me with this ? 你能帮我吗?
This should work: 这应该工作:
#!/bin/bash
read -e -p "Enter the path of the file: " file
./MyPy.py "$file" | grep -vE "^color"
Additional improvement:
其他改进:
If you want to interpret ~
as /home/user
ie use ~/Downloads
to point to /home/user/Downloads
, then: 如果你想诠释
~
为/home/user
即使用~/Downloads
指向/home/user/Downloads
,那么:
#!/bin/bash
read -e -p "Enter the path of the file: " file
file=${file/#\~/$HOME}
./MyPy.py "$file" | grep -vE "^color"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.