Skip to content

Instantly share code, notes, and snippets.

@tuxillo
Created May 13, 2014 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuxillo/2ecf802c374a82fcbb37 to your computer and use it in GitHub Desktop.
Save tuxillo/2ecf802c374a82fcbb37 to your computer and use it in GitHub Desktop.
#! /bin/sh
#set -x
c=1
TOTALFILES=0
DISTFILES="/usr/distfiles"
check_on_files()
{
local compflag=$1
local pattern=$2
for file in ${DISTFILES}/${pattern}
do
if [ ! -f ${file} ]; then
continue
fi
echo "distfile[${c}/${TOTALFILES}] : ${file}"
tar -${compflag} -xOf ${file} | grep ${EXP}
c=`expr $c + 1`
done
}
count_files()
{
TOTALFILES=$(find ${DISTFILES} -maxdepth 1 -type f -iname '*.tar.gz' \
-o -iname '*.tgz' -o -iname '*.tbz2' -o -iname '*.tar.bz2' \
-o -iname '*.txz' -o -iname '*.tar.xz' | wc -l | cut -w -f 2)
}
usage()
{
echo "Usage: distfgrep.sh <regexp>"
exit 1
}
EXP=$@
if [ "${EXP}" == "" ]; then
usage
fi
count_files
check_on_files "z" '*.tar.gz'
check_on_files "z" '*.tgz'
check_on_files "j" '*.tbz2'
check_on_files "j" '*.tar.bz2'
check_on_files "J" '*.txz'
check_on_files "J" '*.tar.xz'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment