Skip to content

Instantly share code, notes, and snippets.

@AttilaVM
Created May 15, 2023 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AttilaVM/f653af3ec6d221d1dd8aeec645ea2cde to your computer and use it in GitHub Desktop.
Save AttilaVM/f653af3ec6d221d1dd8aeec645ea2cde 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}"
while read -r file
do
matches=$(< "$file" jq '.cells[].source[]' -r \
| grep -P "$pattern" || true \
| xargs -I '%' echo -e "\t%"
)
if [ ! -z "$matches" ]
then
echo "$file"
echo "$matches"
fi
done < <(find . \
-type 'f' \
-iname '*.ipynb' \
-not -path '*/.ipynb_checkpoints/*'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment