Last active
January 3, 2019 20:03
-
-
Save mpharrigan/14f3c93be5520d139ea265ad95249663 to your computer and use it in GitHub Desktop.
Clean jupyter notebooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://timstaley.co.uk/posts/making-git-and-jupyter-notebooks-play-nice/ | |
# https://stedolan.github.io/jq/ | |
jq --indent 1 \ | |
' | |
(.cells[] | select(has("outputs")) | .outputs) = [] | |
| (.cells[] | select(has("execution_count")) | .execution_count) = null | |
| .metadata = {"language_info": {"name":"python", "pygments_lexer": "ipython3"}} | |
| .cells[].metadata = {} | |
' notebook.ipynb | |
# annoyingly, this prints to stdout and *can't* be redirected to the same file | |
# as the input without breaking things. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# http://timstaley.co.uk/posts/making-git-and-jupyter-notebooks-play-nice/ | |
# https://stedolan.github.io/jq/ | |
workingfile=`mktemp` | |
jq --indent 1 \ | |
' | |
(.cells[] | select(has("outputs")) | .outputs) = [] | |
| (.cells[] | select(has("execution_count")) | .execution_count) = null | |
| .metadata = {"language_info": {"name":"python", "pygments_lexer": "ipython3"}} | |
| .cells[].metadata = {} | |
' $1 > $workingfile | |
mv $workingfile $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment