Created
May 15, 2023 18:14
-
-
Save AttilaVM/f653af3ec6d221d1dd8aeec645ea2cde 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}" | |
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