Last active
February 23, 2024 12:23
-
-
Save danthe1st/f8e3a7fd93a18b5463aedf8534266911 to your computer and use it in GitHub Desktop.
script for combining find|grep
This file contains hidden or 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 | |
# combination of find and grep | |
# Usage: | |
# findg <text> [<directory>] [<extra args for find>] | |
set -u | |
export SEARCH_STRING="$1" | |
shift | |
if [ $# -eq 0 ]; then | |
TARGET_DIR=. | |
else | |
TARGET_DIR="$1" | |
shift | |
fi | |
function check { | |
file="$1" | |
result="$(grep -i --binary-files=without-match "$SEARCH_STRING" < "$file")" | |
if [ $? = 0 ]; then | |
echo "$file" | |
echo "${result//^/\t}" | |
fi | |
} | |
export -f check | |
find "$TARGET_DIR" -type f "$@" -exec bash -c 'check "{}"' \; 2>/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment