如何在IPython中使用grep?

use*_*093 5 python ipython pythonxy

我安装了PythonXY.我如何在IPython中使用或安装grepgrep类似的功能?它给出了grep未定义的错误.我想在目录中的文本文件中搜索文本.

ska*_*sie 2

假设您在 *nix 系统上,您可以执行以下操作:

文件:file_1.txt

this is line one
this is line two
this is line three
Run Code Online (Sandbox Code Playgroud)

代码:

import os
import subprocess

os.system('grep one file_1.txt')
subprocess.call(['grep', 'one', 'file_1.txt'])
Run Code Online (Sandbox Code Playgroud)

两种情况下的输出:

this is line one
Run Code Online (Sandbox Code Playgroud)