Skip to content

Instantly share code, notes, and snippets.

@maximlt
Created October 7, 2022 13:56
Embed
What would you like to do?
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