# How to search within notebooks on Windows 10?

I have a lot of notebooks scattered in my downloads, documents and desktop folder. I have all the required locations on Windows indexing options but if I look at Advanced Options and File Types and nb extension. I can see it shows

Registered IFilter is not found


Windows search searches for file names and properties but is not searching within the notebooks. Where can I find the IFilters for Wolfram notebooks (version-12) for Windows 10?

Also even if there are no official IFilters, does anyone know how to get windows to use Plain Text Filter for nb file. Since even in plain format nb file opens revealing its box structure.

Since it is by default not encoded and function names don't get transformed in box language, I am happy to search the plain box language but how do I get windows to use Plain Text Filter without attempting any parsing. Since I remember the function names I used in the code that I am looking for in thousands of notebooks.

There is some guy on Wolfram Community saying that: "Spelunking on StackExchange suggests WDS capability was lost back around v10.2. It is a painful loss."

Can someone using version 10.2 or older check whether they are able to search within notebooks on Windows.

Here is a potential workaround.

Windows 10 has a feature called the Windows Subsystem for Linux. You should be able to activate from the start menu and typing "Windows Features" and selecting the first hit. Then, turn it on as shown in the image.

Linux has a command called grep that provides many options to search text files. After installing, you can type bash into the start window and use the bash command shell to search files using grep. For example, the command grep -RH NotebookDirectory --include="*.nb" * will perform a recursive directory search for the term NotebookDirectory for all files matching the pattern *.nb.

I have a Windows 7 and 10 system that both have the Linux emulator Cygwin installed. Since the Windows 10 machine has both Cygwin and the Subsystem for Linux, it can be confusing about which Linux system was called. It turns out that grep is stored in /bin/grep and /usr/bin/grep for the Subsystem for Linux and Cygwin, respectively.

I used the linux command which grep and RunProcess to confirm that my initial answer was picking up the Cygwin grep.

RunProcess[{"which", "grep"}, "StandardOutput"]
(* "/usr/bin/grep" *)


To access the Subsystem for Linux require that we prepend bash -c to the command or

RunProcess[{"bash", "-c", "which grep"}, "StandardOutput"]
(* "/bin/grep" *)


A more robust code that can handle either Cygwin or the Subsystem for Linux follows

SetDirectory[NotebookDirectory[]];
grepRecurse[searchterm_, filepattern_] := {"bash", "-c",
StringTemplate["grep -RH \"1\" --include=\"2\" *"][searchterm,
filepattern]}
cmd = grepRecurse["NotebookDirectory", "Int*.nb"];
s = RunProcess[cmd, "StandardOutput"];
Column@StringSplit[StringSplit[s, RegularExpression["\r?\n"]], ":"][[
All, 1]]


# Original Answer That Might Only Work with Cygwin in Path

Alternatively, you can issue the command from Mathematica directly using RunProcess workflow as shown below.

SetDirectory[NotebookDirectory[]];
grepRecurse[searchterm_, filepattern_] := {"grep", "-RH",
StringTemplate["\"1\""][searchterm],
StringTemplate["--include=\"1\""][filepattern], "*"};
cmd = grepRecurse["NotebookDirectory", "Int*.nb"];
s = RunProcess[cmd, "StandardOutput"];
Column@StringSplit[StringSplit[s, RegularExpression["\r?\n"]],
":"][[All, 1]]


• Are you on windows? is grep safe to use on windows file system? I have installed the subsystem for linux but still getting RunProcess::pnfd: Program grep not found. Check Environment["PATH"]. Do you need to add bash somewhere in your Mathematica code? – user13892 Aug 24 '19 at 16:48
• I have both a Windows 7 and Windows 10 system. Unfortunately, I also have Cygwin installed on both, and that could be causing the discrepancy. If you run RunProcess[{"bash", "-c", "which grep"}, "StandardOutput"] does it return /bin/grep? If it does, then we should be able to adjust the function. – Tim Laska Aug 24 '19 at 17:56
• @user13892 I updated my post. By prepending the command with bash -c, it appears to be picking up the Subsystem for Linux. It has been a while since I installed, but I don't remember doing anything special. Let me know if you still have issues. – Tim Laska Aug 24 '19 at 19:29
• @user13892 Grep by itself should be safe on Windows. As far as I have ever used it, it is read-only. I have been using it a long time (15+ years) on windows because for me it was much faster than File Explorer especially when the directories had 1000s of files. I also checked that Windows installed the Subsystem bash.exe in C:\WINDOWS\system32. – Tim Laska Aug 24 '19 at 21:21
• Thank you your solution works and is very fast. I found the file I was looking for! Since you know how Linux command works, can you also guide me why commands I have added in bash to change the terminal size don't work through the RunProcess interface - see? – user13892 Aug 28 '19 at 11:01

Some time ago I've written a search routine which allows searching inside of Notebooks using string patterns:

Other solutions from that thread can also be of interest for you.

Alternatively you can program your own search routine on the base of one of the following functions:

• Import[nbFilePath, "Plaintext"]

• NotebookImport[nb, _ ->"InputText"]

• First[FrontEndExecute[FrontEndExportPacket[nb, "PlainText"]]]

You can find additional information on their usage in the following threads:

Note however that Import[nbFilePath, "Plaintext"]` is based on "NBImport.exe" which has long-standing bug in importing files with non-ASCII filepaths.

No good news i'm afraid.

The same response is shown for Version 12.0. Assuming they didn't fix it just to break it, the intervening versions are probably bad as well.

If you have defined the functions in an initialization cell and auto-save the ".m" file, this file extension is set up to use plain text search. This is the method i use.

Otherwise, you might be able write a script to resave your files as ".m" and search those file as text.

Best of luck!

Mark