Skip to content

Instantly share code, notes, and snippets.

@ololx
Created October 5, 2023 08:25
Show Gist options
  • Save ololx/6fad7822b50076c6c7981ff0f018cca9 to your computer and use it in GitHub Desktop.
Save ololx/6fad7822b50076c6c7981ff0f018cca9 to your computer and use it in GitHub Desktop.
This is an simple script for grep in txt files and zips
#!/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