Created
May 4, 2022 05:59
-
-
Save qtc-de/4b1e53dcab66d23484d2c03c203ae624 to your computer and use it in GitHub Desktop.
Find filenames within of zip or jar archives
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 | |
function usage() | |
{ | |
NAME=$(basename $0) | |
echo "Usage: $NAME [filter] [path]" | |
echo "" | |
echo "Arguments:" | |
echo " filter regex filter that is applied to archive contents" | |
echo " path path there the search is performed on" | |
echo "" | |
echo "Description:" | |
echo " $NAME can be used to find files within of zip or jar archives. By default, it searches" | |
echo " the current path with no filtering regarding the zip or jar contents. When specifying" | |
echo " a filter, only files matching the filter are shown. Additionally, you can specify a" | |
echo " path to a location where zip or jar files should be serarched." | |
exit 0 | |
} | |
while getopts "h:" arg; do | |
case $arg in | |
h) | |
usage | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
FILTER=$1 | |
S_PATH=$2 | |
find "${S_PATH:=.}" -type f \( -name '*.jar' -or -name '*.zip' \) -print0 | while IFS= read -r -d '' FILE; do | |
UNZIP=$(unzip -l "$FILE") | |
MATCH=$(echo "$UNZIP" | tail -n +2 | grep -i "$FILTER") | |
if [[ $? -eq 0 ]]; then | |
echo -e "\n===========================================================" | |
echo "$UNZIP" | head -n 2 | |
echo "$MATCH" | grep -i "$FILTER" | |
echo "" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment