Is there a more efficient way to do this other than using tar tf
and checking the output of every file against the file that I'm looking for?
This is the way I do it right now, but it's very slow (there are about 600-1000 archives that fit the search_patterns
):
ARRAY=()
ARRAY[0]=/path/to/archives/*search_pattern1*
ARRAY[1]=/path/to/archives/*search_pattern2*
ARRAY[2]=/path/to/archives/*search_pattern3*
for f in ${ARRAY[@]}
do
if [[ $f =~ "matching_pattern1" ]]; then
if tar -tf "$f" | grep "matching_pattern2" ; then
printf "%s\n" $f;
exit 0;
fi
fi
done
For what it's worth, my search_patterns
are 3 consecutive days, and I want first to find the archives that match the matching_pattern1
and then look through all these archives for matching_pattern2
and output the tar
file that contains it.