Auto dectect gzip for catlog

This commit is contained in:
斟酌 鵬兄 2018-05-14 18:57:50 +08:00
parent 5087fdbc74
commit d81aed5899

View File

@ -1,24 +1,21 @@
#!/bin/bash
function catlog () {
if [[ -z "$1" ]]; then
__func_head "[z] FILE"
echo " Will exclude:"
cat ~/.settings/checklog_exclude | awk '{ print " "$1 }'
echo
else
GZIP=false
if [ "$1" == "z" ]; then
GZIP=true
shift
fi
if [[ -z "$1" ]]; then
__func_head "FILE"
echo " Will exclude:"
cat ~/.settings/checklog_exclude | awk '{ print " "$1 }'
echo
else
GZIP=
file "$1" | grep gzip > /dev/null && GZIP=true
EXCLUDE=$(awk '{ printf("(%s)|", $1) }' ~/.settings/checklog_exclude | sed 's/|$//')
EXCLUDE=$(awk '{ printf("(%s)|", $1) }' ~/.settings/checklog_exclude | sed 's/|$//')
if $GZIP; then
gunzip -c $1 | egrep -v $EXCLUDE
else
if [ $GZIP ]; then
gunzip -c $1 | egrep -v $EXCLUDE
else
egrep -v $EXCLUDE $1
fi
fi
fi
fi
}