Created
May 15, 2023 17:38
-
-
Save AttilaVM/e2b71a4a4c0556c2fa6fb8c8183552aa to your computer and use it in GitHub Desktop.
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 | |
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