Skip to content

Instantly share code, notes, and snippets.

@maximlt
Created October 7, 2022 13:56
Show Gist options
  • Save maximlt/a9fa4d19ae5bff83422194ca99533faa to your computer and use it in GitHub Desktop.
Save maximlt/a9fa4d19ae5bff83422194ca99533faa to your computer and use it in GitHub Desktop.
Clean up the output and metadata of a notebook
#!/bin/bash
jq --sort-keys --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 = {}
| del(.cells[].id)
' "$1" > /tmp/$(basename $1) && cat /tmp/$(basename $1) > "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment