I have many jupyter python files (ipnyb), how can I easily search over python source code over them, for example from command line or jupyter-notebook client itself? I am looking for something dedicated to jupter notebooks instead of normal find/grep because embedded data " "data": { "image/png" }
To search inside a notebook, use the find+replace shortcut, F
, in command mode. For example, on Kaggle, Esc
for command mode, then F
to trigger find.
Or open command palette with Cmd+Shift+P
on Mac, Ctrl+Shift+P
on Linux/Win. Then just type "find" in it.
As for searching over multiple notebooks at once within Jupyter, I have no experience. I suggest looking into JupyterLabs and its extensions, since it seems more geared for multiple notebooks.
From CLI, plain grep works
grep wordtosearch *.ipynb
For recursion
grep -r --include \*.ipynb wordtosearch mytopdirectory
This command allow you to perform a recursive search (through all directories from the current directory)
For explanations about this command check this link => explainshell
find . -name '*ipynb' | xargs grep YOUR_SEARCH
I was looking to do this, too! I found a pretty good solution that you can do from within a notebook. The google groups discussion is here, but in case the link breaks, here is the code provided there:
pattern = '../**/*.ipynb'
query = 'text you want to find'
for filepath in glob.iglob(pattern, recursive=True):
with open(filepath) as file:
s = file.read()
if (s.find(query) > -1):
print(filepath)
This will print all of the files that contain the search string. A nice enhancement would be to also print the context in which the string occurs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With