summaryrefslogtreecommitdiffstats
path: root/zgrep.in
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 16:11:02 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 16:11:02 +0000
commit4e47773f0570bdffefd062b85265242f9f13ef96 (patch)
tree815a38d504a9005ddd7f548c0067a43172f05a02 /zgrep.in
parentAdding upstream version 0.3. (diff)
downloadzutils-4e47773f0570bdffefd062b85265242f9f13ef96.tar.xz
zutils-4e47773f0570bdffefd062b85265242f9f13ef96.zip
Adding upstream version 0.4.upstream/0.4
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'zgrep.in')
-rw-r--r--zgrep.in51
1 files changed, 26 insertions, 25 deletions
diff --git a/zgrep.in b/zgrep.in
index 7321bdb..228cbd9 100644
--- a/zgrep.in
+++ b/zgrep.in
@@ -27,6 +27,9 @@ while [ x"$1" != x ] ; do
echo "names corresponding to the supported compressors."
echo "The supported compressors are gzip, bzip2, lzip and xz."
echo
+ echo "Zegrep is a shortcut for \"zgrep -E\""
+ echo "Zfgrep is a shortcut for \"zgrep -F\""
+ echo
echo "Usage: $0 [OPTIONS] [GREP_OPTIONS] PATTERN [FILES]"
echo
echo "GREP_OPTIONS are passed directly to grep."
@@ -81,28 +84,26 @@ retval=0
for i in "$@" ; do
if [ "$i" = "--" ] && [ ${two_hyphens} = 0 ] ; then two_hyphens=1
else
- if [ -f "$i" ]; then
- case "$i" in
- *.gz | *.tgz)
- prog="gzip -cdfq" ;;
- *.bz2 | *.tbz | *.tbz2)
- prog="bzip2 -cdfq" ;;
- *.lz | *.tlz)
- prog="lzip -cdfq" ;;
- *.xz | *.txz)
- prog="xz -cdfq" ;;
- *)
- prog=cat ;;
- esac
- elif [ -f "$i.gz" ]; then i="$i.gz" ; prog="gzip -cdfq"
- elif [ -f "$i.bz2" ]; then i="$i.bz2" ; prog="bzip2 -cdfq"
- elif [ -f "$i.lz" ]; then i="$i.lz" ; prog="lzip -cdfq"
- elif [ -f "$i.xz" ]; then i="$i.xz" ; prog="xz -cdfq"
- else
- echo "$0: File \"$i\" not found or not a regular file" 1>&2
- if [ ${retval} = 0 ]; then retval=1 ; fi
- continue
+ if [ ! -f "$i" ]; then
+ if [ -f "$i.gz" ]; then i="$i.gz"
+ elif [ -f "$i.bz2" ]; then i="$i.bz2"
+ elif [ -f "$i.lz" ]; then i="$i.lz"
+ elif [ -f "$i.xz" ]; then i="$i.xz"
+ else
+ echo "$0: File \"$i\" not found or not a regular file" 1>&2
+ if [ ${retval} = 0 ]; then retval=1 ; fi
+ continue
+ fi
fi
+ bindir=`echo "$0" | sed -e 's,[^/]*$,,'`
+ prog_name=`"${bindir}"zutils -t -- "$i"`
+ case "${prog_name}" in
+ gzip) prog="gzip -cdfq" ;;
+ bzip2) prog="bzip2 -cdfq" ;;
+ lzip) prog="lzip -cdfq" ;;
+ xz) prog="xz -cdfq" ;;
+ *) prog=cat ;;
+ esac
if [ ${list} = 1 ]; then
${prog} -- "$i" | grep ${args} 2>&1 > /dev/null && echo "$i"
r=$?
@@ -110,11 +111,11 @@ for i in "$@" ; do
${prog} -- "$i" | grep ${args}
r=$?
else
- j=`printf "%s" "$i" | sed 's/\\\\/\\\\\\\\/g'`
- j=`printf "%s" "$j" | sed 's/|/\\\\|/g'`
- j=`printf "%s" "$j" | sed 's/&/\\\\&/g'`
+ j=`printf "%s" "$i" | sed -e 's,\\\\,\\\\\\\\,g'`
+ j=`printf "%s" "$j" | sed -e 's,|,\\\\|,g'`
+ j=`printf "%s" "$j" | sed -e 's,&,\\\\&,g'`
j=`printf "%s" "$j" | tr '\n' ' '`
- ${prog} -- "$i" | grep ${args} | sed "s|^|${j}:|"
+ ${prog} -- "$i" | grep ${args} | sed -e "s,^,${j}:,"
r=$?
fi
[ $r != 0 ] && retval="$r"