Created
October 5, 2023 08:25
-
-
Save ololx/6fad7822b50076c6c7981ff0f018cca9 to your computer and use it in GitHub Desktop.
This is an simple script for grep in txt files and zips
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 | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 [PATH_TO_FOLDER] [SEARCH_STRING]" | |
exit 1 | |
fi | |
SRC_DIR="$1" | |
SEARCH_STRING="$2" | |
START_TIME=$SECONDS | |
grep -Ir "$SEARCH_STRING" "$SRC_DIR" | |
find "$SRC_DIR" -type f -name '*.zip' | while read -r zipfile | |
do | |
unzip -p "$zipfile" | grep --with-filename --label="$zipfile" "$SEARCH_STRING" | |
done | |
ELAPSED_TIME=$(($SECONDS - $START_TIME)) | |
echo "Total elapsed time: $ELAPSED_TIME seconds." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment