nbconvert has a preprocessor that clears cell outputs from notebook files, leaving cell inputs intact.
The following shell command reads my_input_notebook.ipynb
, removes its cell outputs, prints the cleaned notebook to stdout, and redirects that output to a new notebook file named my_output_notebook.ipynb
.
jupyter nbconvert my_input_notebook.ipynb --to notebook --ClearOutputPreprocessor.enabled=True --stdout > my_output_notebook.ipynb