Skip to content

Instantly share code, notes, and snippets.

@AttilaVM
Created May 15, 2023 17:38
Show Gist options
  • Save AttilaVM/e2b71a4a4c0556c2fa6fb8c8183552aa to your computer and use it in GitHub Desktop.
Save AttilaVM/e2b71a4a4c0556c2fa6fb8c8183552aa to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
catch() {
echo "ERROR $1 occurred on $2"
}
trap 'catch $? $LINENO' ERR
pattern="${1? You must provide a search pattern}"
jupyter-search() {
file="$1"
pattern="$2"
matches=$(< "$file" jq '.cells[].source[]' -r \
| grep -P "$pattern" \
| xargs -I '%' echo -e "\t%"
)
if [ ! -z "$matches" ]
then
echo "$file"
echo "$matches"
fi
}
export -f jupyter-search
find . \
-type 'f' \
-iname '*.ipynb' \
-not -path '*/.ipynb_checkpoints/*'\
| parallel jupyter-search {} "$pattern"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment